site_head.html 15 KB

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