site_head.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. {{ $is_sponsor := site.Params.i_am_a_sponsor | default false }}
  6. {{ $hide_generator := site.Params.power_ups.hide_generator | default false }}
  7. {{ if not (and $is_sponsor $hide_generator) }}
  8. <meta name="generator" content="Wowchemy {{ site.Data.wowchemy.version }} for Hugo" />
  9. {{ end }}
  10. {{ with site.Params.marketing.google_site_verification }}
  11. <meta name="google-site-verification" content="{{ . }}" />
  12. {{- end -}}
  13. {{ $scr := .Scratch }}
  14. {{ $media_dir := site.Params.media_dir | default "media" }}
  15. {{ $scr.Set "media_dir" $media_dir }}
  16. {{/* Attempt to load superuser. */}}
  17. {{ $superuser_name := "" }}
  18. {{ $superuser_username := "" }}
  19. {{ $superuser_role := "" }}
  20. {{ range first 1 (where (where site.Pages "Section" "authors") "Params.superuser" true) }}
  21. {{ $superuser_name = .Title }}
  22. {{ $superuser_username = path.Base (path.Split .Path).Dir }}
  23. {{ $superuser_role = .Params.role }}
  24. {{ end }}
  25. {{ $scr.Set "superuser_username" $superuser_username }}{{/* Set superuser globally for page_author.html. */}}
  26. {{ with $superuser_name }}<meta name="author" content="{{ . }}" />{{ end }}
  27. {{/* Generate page description. */}}
  28. {{ $desc := "" }}
  29. {{ if .Params.summary }}
  30. {{ $desc = .Params.summary }}
  31. {{ else if .Params.abstract }}
  32. {{ $desc = .Params.abstract }}
  33. {{ else if .IsPage }}
  34. {{ $desc = .Summary }}
  35. {{ else if site.Params.description }}
  36. {{ $desc = site.Params.description }}
  37. {{ else }}
  38. {{ $desc = $superuser_role }}
  39. {{ end }}
  40. <meta name="description" content="{{ $desc }}" />
  41. {{ range .Translations }}
  42. <link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}" />
  43. {{ end }}
  44. <link rel="alternate" hreflang="{{ site.LanguageCode | default "en-us" }}" href="{{ .Permalink }}" />
  45. {{ partial "functions/parse_theme" . }}
  46. {{/* Pre-connect to Google Fonts if the site's Font Theme uses them. */}}
  47. {{ with ($scr.Get "google_fonts") }}
  48. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  49. {{ end }}
  50. {{ $css := site.Data.assets.css }}
  51. {{ $js := site.Data.assets.js }}
  52. {{ if ne ($scr.Get "primary") "#fff" }}
  53. <meta name="theme-color" content="{{ $scr.Get "primary" }}" />
  54. {{ end }}
  55. {{/* Config LaTeX math rendering. */}}
  56. {{ if or .Params.math site.Params.math }}
  57. {{ $mathjax_config := resources.Get "js/mathjax-config.js" }}
  58. <script src="{{ $mathjax_config.RelPermalink }}"></script>
  59. {{ end }}
  60. {{/* Attempt to load local vendor CSS, otherwise load from CDN. */}}
  61. {{ $scr.Set "vendor_css_filename" "main.min.css" }}
  62. {{ $scr.Set "vendor_js_filename" "main.min.js" }}
  63. {{ if and (fileExists (printf "static/css/vendor/%s" ($scr.Get "vendor_css_filename"))) (fileExists (printf "static/js/vendor/%s" ($scr.Get "vendor_js_filename"))) }}
  64. {{ $scr.Set "use_cdn" 0 }}
  65. <link rel="stylesheet" href="{{ printf "/css/vendor/%s" ($scr.Get "vendor_css_filename") | relURL }}" />
  66. {{ else }}
  67. {{ $scr.Set "use_cdn" 1 }}
  68. {{ if site.Params.icon.pack.ai }}
  69. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.academicons.url $css.academicons.version) $css.academicons.sri | safeHTML }}
  70. {{ end }}
  71. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.fontAwesome.url $css.fontAwesome.version) $css.fontAwesome.sri | safeHTML }}
  72. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" media=\"print\" onload=\"this.media='all'\">" (printf $css.fancybox.url $css.fancybox.version) $css.fancybox.sri | safeHTML }}
  73. {{/* Default to disabling highlighting, but allow the user to override it in .Params or site.Params.
  74. Use $scr to store "highlight_enabled", so that we can read it again in footer.html. */}}
  75. {{ $scr.Set "highlight_enabled" false }}
  76. {{ if isset .Params "highlight" }}
  77. {{ $scr.Set "highlight_enabled" .Params.highlight }}
  78. {{ else if isset site.Params "highlight" }}
  79. {{ $scr.Set "highlight_enabled" site.Params.highlight }}
  80. {{ end }}
  81. {{ if ($scr.Get "highlight_enabled") }}
  82. {{ $v := $css.highlight.version }}
  83. {{ with site.Params.highlight_style }}
  84. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-light\" media=\"print\" onload=\"this.media='all'\">" (printf $css.highlight.url $css.highlight.version .) | safeHTML }}
  85. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-dark\" media=\"print\" onload=\"this.media='all'\" disabled>" (printf $css.highlight.url $css.highlight.version .) | safeHTML }}
  86. {{ else }}
  87. {{ if eq ($scr.Get "light") true }}
  88. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-light\" media=\"print\" onload=\"this.media='all'\">" (printf $css.highlight.url $css.highlight.version "github") | safeHTML }}
  89. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-dark\" media=\"print\" onload=\"this.media='all'\" disabled>" (printf $css.highlight.url $css.highlight.version "dracula") | safeHTML }}
  90. {{ else }}
  91. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-light\" media=\"print\" onload=\"this.media='all'\" disabled>" (printf $css.highlight.url $css.highlight.version "github") | safeHTML }}
  92. {{ printf "<link rel=\"stylesheet\" href=\"%s\" crossorigin=\"anonymous\" title=\"hl-dark\" media=\"print\" onload=\"this.media='all'\">" (printf $css.highlight.url $css.highlight.version "dracula") | safeHTML }}
  93. {{ end }}
  94. {{ end }}
  95. {{ end }}
  96. {{ if or (eq site.Params.map.engine 2) (eq site.Params.map.engine 3) }}
  97. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" media=\"print\" onload=\"this.media='all'\">" (printf $css.leaflet.url $css.leaflet.version) $css.leaflet.sri | safeHTML }}
  98. {{ end }}
  99. {{ if eq site.Params.search.engine 2 }}
  100. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.instantsearch.url $css.instantsearch.version) $css.instantsearch.sri | safeHTML }}
  101. {{ printf "<link rel=\"stylesheet\" href=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\">" (printf $css.instantsearchTheme.url $css.instantsearchTheme.version) $css.instantsearchTheme.sri | safeHTML }}
  102. {{ end }}
  103. {{/* Load async scripts. */}}
  104. {{ range $k, $v := site.Data.assets.js }}
  105. {{/* TODO: investigate why `where ... "async" true` does not work. */}}
  106. {{ $load := $v.async }}
  107. {{/* Only load MathJax if required. */}}
  108. {{ if (eq $k "mathJax") | and (not (or $.Params.math site.Params.math)) }}
  109. {{ $load = false }}
  110. {{ end }}
  111. {{ if $load }}
  112. {{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\" async></script>" (printf $v.url $v.version) $v.sri | safeHTML }}
  113. {{ end }}
  114. {{ end }}
  115. {{ end }}
  116. {{/* Load Google Fonts if the site's Font Theme uses them. */}}
  117. {{/* Note: we cannot use SRI with Google Fonts because the CSS is dynamically generated according to the user agent. */}}
  118. {{ with ($scr.Get "google_fonts") }}
  119. {{ if hasPrefix . "family=" }}
  120. {{/* If `google_fonts` starts with "family=", use API v2 (https://developers.google.com/fonts/docs/css2) */}}
  121. <link rel="preload" as="style" {{ printf "href=\"https://fonts.googleapis.com/css2?%s&display=swap\"" . | safeHTMLAttr }}>
  122. <link rel="stylesheet" {{ printf "href=\"https://fonts.googleapis.com/css2?%s&display=swap\"" . | safeHTMLAttr }} media="print" onload="this.media='all'">
  123. {{ else }}
  124. {{/* Otherwise, use API v1 */}}
  125. {{/* Hugo's htmlEscape cannot escape "|" in Google Font URIs so we implement our own escape functionality. */}}
  126. <link rel="stylesheet" {{ printf "href=\"https://fonts.googleapis.com/css?family=%s&display=swap\"" . | replaceRE "\\|" "%7C" | safeHTMLAttr }}>
  127. {{ warnf "There is a new version of Google Fonts. Learn how to upgrade your font pack at https://wowchemy.com/docs/customization/#custom-font" }}
  128. {{ end }}
  129. {{ end }}
  130. {{ $license := printf "/*! Wowchemy v%s | https://wowchemy.com/ */\n" site.Data.wowchemy.version }}
  131. {{ $license := $license | printf "%s/*! Copyright 2016-present George Cushen (https://georgecushen.com/) */\n" }}
  132. {{ $license := $license | printf "%s/*! License: https://github.com/wowchemy/wowchemy-hugo-modules/blob/master/LICENSE.md */\n" }}
  133. {{ $css_bundle_head := $license | resources.FromString "css/bundle-head.css" }}
  134. {{ $css_options := dict "targetPath" "css/wowchemy.css" }}
  135. {{- if eq hugo.Environment "production" -}}
  136. {{- $css_options = merge $css_options (dict "outputStyle" "compressed") -}}
  137. {{- end -}}
  138. {{ $sass_template := resources.Get "scss/main.scss" }}
  139. {{ $style := $sass_template | resources.ExecuteAsTemplate "main_parsed.scss" . | toCSS $css_options }}
  140. {{- if eq hugo.Environment "production" -}}
  141. {{- $style = $style | minify -}}
  142. {{- end -}}
  143. {{ $style := slice $css_bundle_head $style | resources.Concat "css/wowchemy.css" }}
  144. {{- if eq (getenv "WC_POST_CSS") "true" -}}
  145. {{- $style = $style | postCSS -}}
  146. {{- end -}}
  147. {{- if eq hugo.Environment "production" -}}
  148. {{- $style = $style | fingerprint "md5" -}}
  149. {{- end -}}
  150. <link rel="stylesheet" href="{{ $style.RelPermalink }}" />
  151. {{ partial "marketing/google_analytics" . }}
  152. {{ partial "marketing/google_tag_manager" . }}
  153. {{ partial "marketing/microsoft_clarity" . }}
  154. {{/* Netlify Identity integration. */}}
  155. {{ $use_cms := templates.Exists "wowchemycms/single.wowchemycms_config.yml" | default (site.Params.cms.netlify_cms | default false) }}
  156. {{ if .IsHome | and $use_cms }}
  157. <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
  158. {{ end }}
  159. {{ with .OutputFormats.Get "RSS" }}
  160. <link rel="alternate" href="{{ .RelPermalink }}" type="application/rss+xml" title="{{ site.Title }}" />
  161. {{ end }}
  162. {{ if site.Home.OutputFormats.Get "WebAppManifest" }}
  163. <link rel="manifest" href="{{ "index.webmanifest" | relLangURL }}" />
  164. {{ end }}
  165. <link rel="icon" type="image/png" href="{{ (partial "functions/get_icon" 32).RelPermalink }}" />
  166. <link rel="apple-touch-icon" type="image/png" href="{{ (partial "functions/get_icon" 180).RelPermalink }}" />
  167. <link rel="canonical" href="{{ .Permalink }}" />
  168. {{/* Get page image for sharing. */}}
  169. {{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }}
  170. {{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }}
  171. {{ $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") }}
  172. {{ $og_image := "" }}
  173. {{ $twitter_card := "summary_large_image" }}
  174. {{ if (and (eq .Kind "term") $avatar_image) }}
  175. {{/* Match image processing in About widget to prevent generating more images than necessary. */}}
  176. {{ $og_image = ($avatar_image.Fill "270x270 Center").Permalink }}
  177. {{ $twitter_card = "summary" }}
  178. {{ else if $featured_image }}
  179. {{ $og_image = $featured_image.Permalink }}
  180. {{ else if .Params.header.image }}
  181. {{ $og_image = printf "%s/%s" $media_dir .Params.header.image | absURL }}
  182. {{ else if site.Params.sharing_image }}
  183. {{ $og_image = printf "%s/%s" $media_dir site.Params.sharing_image | absURL }}
  184. {{ else if $has_logo }}
  185. {{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }}
  186. {{ $twitter_card = "summary" }}
  187. {{ else }}
  188. {{ $og_image = (partial "functions/get_icon" 512).Permalink }}
  189. {{ $twitter_card = "summary" }}
  190. {{ end }}
  191. {{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}}
  192. <meta property="twitter:card" content="{{ $twitter_card }}" />
  193. {{ with site.Params.twitter }}
  194. <meta property="twitter:site" content="@{{ . }}" />
  195. <meta property="twitter:creator" content="@{{ . }}" />
  196. {{ end }}
  197. <meta property="og:site_name" content="{{ site.Title }}" />
  198. <meta property="og:url" content="{{ .Permalink }}" />
  199. <meta property="og:title" content="{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}" />
  200. <meta property="og:description" content="{{ $desc }}" />
  201. {{- with $og_image -}}
  202. <meta property="og:image" content="{{ . }}" />
  203. <meta property="twitter:image" content="{{ . }}" />
  204. {{- end -}}
  205. <meta property="og:locale" content="{{ site.LanguageCode | default "en-us" }}" />
  206. {{ if .IsPage }}
  207. {{ if not .PublishDate.IsZero }}
  208. <meta
  209. property="article:published_time"
  210. content="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"
  211. />
  212. {{ else if not .Date.IsZero }}
  213. <meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}" />
  214. {{ end }}
  215. {{ if not .Lastmod.IsZero }}<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">{{ end }}
  216. {{ else }}
  217. {{ if not .Date.IsZero }}
  218. <meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}" />
  219. {{ end }}
  220. {{ end }}
  221. {{ partial "jsonld/main" (dict "page" . "summary" $desc) }}
  222. {{ partial "cookie_consent" . }}
  223. {{ partial "custom_head" . }}
  224. <title>{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}</title>
  225. </head>