header.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html lang="{{ .Site.LanguageCode }}">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- Title -->
  8. <title>
  9. {{- if not .IsHome }}
  10. {{- if eq .Kind "page" }}{{ .Title }}
  11. {{- else if eq .Data.Singular "tag" }}{{ .Data.Term }}
  12. {{- else }}Posts
  13. {{- end }} - {{ end }}
  14. {{- .Site.Title -}}
  15. </title>
  16. <!-- Meta -->
  17. {{- if eq .Kind "page" }}
  18. <meta name="description" content="{{ .Summary }}">
  19. <meta name="author" content="{{ .Params.author | default .Site.Params.author }}">
  20. {{ else }}
  21. <meta name="description" content="{{ .Site.Params.description }}">
  22. <meta name="author" content="{{ .Site.Params.author }}">
  23. {{ end -}}
  24. <!-- Styles -->
  25. <link href="{{ "an-old-hope.min.css" | absURL }}" rel="stylesheet">
  26. <link href="{{ "style.css" | absURL }}" rel="stylesheet">
  27. <!-- Favicons -->
  28. <link rel="apple-touch-icon" href="{{ "apple-touch-icon.png" | absURL }}">
  29. <link rel="icon" href="{{ "favicon.ico" | absURL }}">
  30. <!-- Generator -->
  31. {{ hugo.Generator }}
  32. <!-- RSS -->
  33. <link rel="alternate" type="application/atom+xml" href="{{ "index.xml" | absURL }}" title="{{ .Site.Title }}">
  34. <!-- Misc -->
  35. {{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }}
  36. {{ end }}
  37. <!-- Script -->
  38. <script>
  39. function setTheme() {
  40. const time = new Date();
  41. const prev = localStorage.getItem('date');
  42. const date = String(time.getMonth() + 1) + '.' + String(time.getDate());
  43. const now = time.getTime();
  44. let sunrise;
  45. let sunset;
  46. function setBodyClass() {
  47. if (now > sunrise && now < sunset) return;
  48. document.body.classList.add('dark');
  49. }
  50. if (date !== prev) {
  51. fetch('https://api.ipgeolocation.io/astronomy?apiKey=5ed37d85103e4defa5df4c5298ed5215')
  52. .then(res => res.json())
  53. .then(data => {
  54. sunrise = data.sunrise.split(':').map(Number);
  55. sunset = data.sunset.split(':').map(Number);
  56. })
  57. .catch(() => {
  58. sunrise = [7, 0];
  59. sunset = [19, 0];
  60. })
  61. .finally(() => {
  62. sunrise = time.setHours(sunrise[0], sunrise[1], 0);
  63. sunset = time.setHours(sunset[0], sunset[1], 0);
  64. setBodyClass();
  65. localStorage.setItem('sunrise', sunrise);
  66. localStorage.setItem('sunset', sunset);
  67. });
  68. localStorage.setItem('date', date);
  69. } else {
  70. sunrise = Number(localStorage.getItem('sunrise'));
  71. sunset = Number(localStorage.getItem('sunset'));
  72. setBodyClass();
  73. }
  74. }
  75. </script>
  76. </head>
  77. <body class="{{if eq .Kind `page` }}single{{else}}list{{ if .IsHome }} home{{ end }}{{end}}">
  78. <script>
  79. setTheme();
  80. </script>
  81. <header class="header">
  82. <nav class="nav">
  83. {{ if .IsHome }}
  84. <h1 class="logo"><a href="{{ "" | absURL }}">{{ .Site.Title }}</a></h1>
  85. {{ else }}
  86. <p class="logo"><a href="{{ "" | absURL }}">{{ .Site.Title }}</a></p>
  87. {{ end }}
  88. {{ if .Site.Menus.main }}
  89. <ul class="menu">
  90. {{ range .Site.Menus.main }}
  91. <li>
  92. <a href="{{ .URL }}">{{ .Name }}</a>
  93. </li>
  94. {{ end }}
  95. </ul>
  96. {{ end }}
  97. </nav>
  98. </header>
  99. <main class="main">