site_head.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <head>
  2. <meta charset="utf-8">
  3. <meta name="viewport" content="width=device-width, initial-scale=1">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="generator" content="Source Themes Academic {{ site.Data.academic.version }}">
  6. {{ $scr := .Scratch }}
  7. {{/* Attempt to load superuser. */}}
  8. {{ $superuser_name := "" }}
  9. {{ $superuser_username := "" }}
  10. {{ $superuser_role := "" }}
  11. {{ range first 1 (where (where site.Pages "Section" "authors") "Params.superuser" true) }}
  12. {{ $superuser_name = .Params.name }}
  13. {{ $superuser_username = path.Base (path.Split .Path).Dir }}
  14. {{ $superuser_role = .Params.role }}
  15. {{ end }}
  16. {{ $scr.Set "superuser_username" $superuser_username }}{{/* Set superuser globally for page_author.html. */}}
  17. {{ with $superuser_name }}<meta name="author" content="{{ . }}">{{ end }}
  18. {{/* Generate page description. */}}
  19. {{ $desc := "" }}
  20. {{ if .Params.summary }}
  21. {{ $desc = .Params.summary }}
  22. {{ else if .Params.abstract }}
  23. {{ $desc = .Params.abstract }}
  24. {{ else if .IsPage }}
  25. {{ $desc = .Summary }}
  26. {{ else if site.Params.description }}
  27. {{ $desc = site.Params.description }}
  28. {{ else }}
  29. {{ $desc = $superuser_role }}
  30. {{ end }}
  31. <meta name="description" content="{{ $desc }}">
  32. {{ range .Translations }}
  33. <link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
  34. {{ end }}
  35. <link rel="alternate" hreflang="{{ site.LanguageCode | default "en-us" }}" href="{{ .Permalink }}">
  36. {{ partial "functions/parse_theme" . }}
  37. {{ $css := site.Data.assets.css }}
  38. {{ $js := site.Data.assets.js }}
  39. {{ if ne ($scr.Get "primary") "#fff" }}
  40. <meta name="theme-color" content="{{ $scr.Get "primary" }}">
  41. {{ end }}
  42. {{/* Config LaTeX math rendering. */}}
  43. {{ if or .Params.math site.Params.math }}
  44. {{ $mathjax_config := resources.Get "js/mathjax-config.js" }}
  45. <script src="{{ $mathjax_config.RelPermalink }}"></script>
  46. {{ end }}
  47. {{/* Attempt to load local vendor CSS, otherwise load from CDN. */}}
  48. {{ $scr.Set "vendor_css_filename" "main.min.css" }}
  49. {{ $scr.Set "vendor_js_filename" "main.min.js" }}
  50. {{ if and (fileExists (printf "static/css/vendor/%s" ($scr.Get "vendor_css_filename"))) (fileExists (printf "static/js/vendor/%s" ($scr.Get "vendor_js_filename"))) }}
  51. {{ $scr.Set "use_cdn" 0 }}
  52. <link rel="stylesheet" href="{{ printf "/css/vendor/%s" ($scr.Get "vendor_css_filename") | relURL }}">
  53. {{ else }}
  54. {{ $scr.Set "use_cdn" 1 }}
  55. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.academicons.url $css.academicons.version) $css.academicons.sri | safeHTML }}
  56. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.fontAwesome.url $css.fontAwesome.version) $css.fontAwesome.sri | safeHTML }}
  57. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.fancybox.url $css.fancybox.version) $css.fancybox.sri | safeHTML }}
  58. {{/* Default to enabling highlighting, but allow the user to override it in .Params or site.Params.
  59. Use $scr to store "highlight_enabled", so that we can read it again in footer.html. */}}
  60. {{ $scr.Set "highlight_enabled" true }}
  61. {{ if isset .Params "highlight" }}
  62. {{ $scr.Set "highlight_enabled" .Params.highlight }}
  63. {{ else if isset site.Params "highlight" }}
  64. {{ $scr.Set "highlight_enabled" site.Params.highlight }}
  65. {{ end }}
  66. {{ if ($scr.Get "highlight_enabled") }}
  67. {{ $v := $css.highlight.version }}
  68. {{ with site.Params.highlight_style }}
  69. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-light\">" (printf $css.highlight.url $css.highlight.version .) | safeHTML }}
  70. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-dark\" disabled>" (printf $css.highlight.url $css.highlight.version .) | safeHTML }}
  71. {{ else }}
  72. {{ if eq ($scr.Get "light") true }}
  73. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-light\">" (printf $css.highlight.url $css.highlight.version "github") | safeHTML }}
  74. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-dark\" disabled>" (printf $css.highlight.url $css.highlight.version "dracula") | safeHTML }}
  75. {{ else }}
  76. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-light\" disabled>" (printf $css.highlight.url $css.highlight.version "github") | safeHTML }}
  77. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-dark\">" (printf $css.highlight.url $css.highlight.version "dracula") | safeHTML }}
  78. {{ end }}
  79. {{ end }}
  80. {{ end }}
  81. {{ if or (eq site.Params.map.engine 2) (eq site.Params.map.engine 3) }}
  82. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.leaflet.url $css.leaflet.version) $css.leaflet.sri | safeHTML }}
  83. {{ end }}
  84. {{ if eq site.Params.search.engine 2 }}
  85. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.instantsearch.url $css.instantsearch.version) $css.instantsearch.sri | safeHTML }}
  86. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.instantsearchTheme.url $css.instantsearchTheme.version) $css.instantsearchTheme.sri | safeHTML }}
  87. {{ end }}
  88. {{/* Load async scripts. */}}
  89. {{ range $k, $v := site.Data.assets.js }}{{/* TODO: investigate why `where ... "async" true` does not work. */}}
  90. {{ $load := $v.async }}
  91. {{/* Only load MathJax if required. */}}
  92. {{ if (eq $k "mathJax") | and (not (or $.Params.math site.Params.math)) }}
  93. {{ $load = false }}
  94. {{end}}
  95. {{ if $load }}
  96. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" async></script>" (printf $v.url $v.version) $v.sri | safeHTML }}
  97. {{end}}
  98. {{end}}
  99. {{ end }}
  100. {{/* We cannot use SRI with Google Fonts because the CSS is dynamically generated according to the user agent. */}}
  101. {{/* Hugo's htmlEscape cannot escape "|" in Google Font URIs so we implement our own escape functionality. */}}
  102. {{ with ($scr.Get "google_fonts") }}
  103. <link rel="stylesheet" {{ printf "href=\"https://fonts.googleapis.com/css?family=%s&display=swap\"" . | replaceRE "\\|" "%7C" | safeHTMLAttr }}>
  104. {{ end }}
  105. {{ $css_comment := printf "/*!* Source Themes Academic v%s (https://sourcethemes.com/academic/) */\n" site.Data.academic.version }}
  106. {{ $css_bundle_head := $css_comment | resources.FromString "css/bundle-head.css" }}
  107. {{ $css_options := dict "targetPath" "css/academic.css" }}
  108. {{- if (in (slice (getenv "HUGO_ENV") hugo.Environment) "production") -}}
  109. {{- $css_options = merge $css_options (dict "outputStyle" "compressed") -}}
  110. {{- end -}}
  111. {{ $sass_template := resources.Get "scss/main.scss" }}
  112. {{ $style := $sass_template | resources.ExecuteAsTemplate "main_parsed.scss" . | toCSS $css_options }}
  113. {{ $style := slice $css_bundle_head $style | resources.Concat "css/academic.css" }}
  114. {{- if (eq (getenv "HUGO_ENV") "production") -}}
  115. {{- $style = $style | minify | fingerprint "md5" -}}
  116. {{- end -}}
  117. <link rel="stylesheet" href="{{ $style.RelPermalink }}">
  118. {{ partial "marketing/google_analytics" . }}
  119. {{ partial "marketing/google_tag_manager" . }}
  120. {{ with .OutputFormats.Get "RSS" }}
  121. <link rel="alternate" href="{{.RelPermalink}}" type="application/rss+xml" title="{{site.Title}}">
  122. {{ end }}
  123. <link rel="manifest" href="{{ "index.webmanifest" | relLangURL }}">
  124. <link rel="icon" type="image/png" href="{{(partial "functions/get_icon" 32).RelPermalink}}">
  125. <link rel="apple-touch-icon" type="image/png" href="{{(partial "functions/get_icon" 192).RelPermalink}}">
  126. <link rel="canonical" href="{{ .Permalink }}">
  127. {{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }}
  128. {{ $og_image := "" }}
  129. {{ $twitter_card := "summary_large_image" }}
  130. {{ if $featured_image }}
  131. {{ $og_image = $featured_image.Permalink }}
  132. {{ else if .Params.header.image }}
  133. {{ $og_image = printf "img/%s" .Params.header.image | absURL }}
  134. {{ else if site.Params.sharing_image }}
  135. {{ $og_image = printf "img/%s" site.Params.sharing_image | absURL }}
  136. {{ else if site.Params.logo }}
  137. {{ $og_image = (printf "img/%s" site.Params.logo) | absURL }}
  138. {{ $twitter_card = "summary" }}
  139. {{ else if site.Params.avatar }}
  140. {{ $og_image = (printf "img/%s" site.Params.avatar) | absURL }}
  141. {{ $twitter_card = "summary" }}
  142. {{ else }}
  143. {{ $og_image = (partial "functions/get_icon" 512).Permalink }}
  144. {{ $twitter_card = "summary" }}
  145. {{ end }}
  146. {{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}}
  147. <meta property="twitter:card" content="{{ $twitter_card }}">
  148. {{ with site.Params.twitter }}
  149. <meta property="twitter:site" content="@{{ . }}">
  150. <meta property="twitter:creator" content="@{{ . }}">
  151. {{ end }}
  152. <meta property="og:site_name" content="{{ site.Title }}">
  153. <meta property="og:url" content="{{ .Permalink }}">
  154. <meta property="og:title" content="{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}">
  155. <meta property="og:description" content="{{ $desc }}">
  156. {{- with $og_image -}}
  157. <meta property="og:image" content="{{.}}">
  158. <meta property="twitter:image" content="{{.}}">
  159. {{- end -}}
  160. <meta property="og:locale" content="{{ site.LanguageCode | default "en-us" }}">
  161. {{ if .IsPage }}
  162. {{ if not .PublishDate.IsZero }}
  163. <meta property="article:published_time" content="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">
  164. {{ else if not .Date.IsZero }}
  165. <meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">
  166. {{ end }}
  167. {{ if not .Lastmod.IsZero }}<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">{{ end }}
  168. {{ else }}
  169. {{ if not .Date.IsZero }}<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">{{ end }}
  170. {{ end }}
  171. {{ partial "jsonld/main" (dict "page" . "summary" $desc) }}
  172. {{ partial "cookie_consent" . }}
  173. {{ partial "custom_head" . }}
  174. <title>{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}</title>
  175. </head>