hextra/layouts/partials/head.html
Xin 8021437f77
chore: use CDN to download mermaid js (#651)
* chore: download js assets during build time

* chore: remove CDN asset download task and update Mermaid script fingerprinting
2025-03-30 21:20:50 +01:00

80 lines
2.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{{ if hugo.IsProduction -}}
<meta name="robots" content="index, follow" />
{{ else -}}
<meta name="robots" content="noindex, nofollow" />
{{ end -}}
{{ partialCached "favicons.html" . -}}
<title>
{{- if .IsHome -}}
{{ .Site.Title -}}
{{ else -}}
{{ with .Title }}{{ . }} {{ end -}}
{{ .Site.Title -}}
{{ end -}}
</title>
<meta name="description" content="{{ partial "utils/page-description.html" . }}" />
{{- with .Params.canonical -}}
<link rel="canonical" href="{{ . }}" itemprop="url" />
{{- else -}}
<link rel="canonical" href="{{ .Permalink }}" itemprop="url" />
{{- end -}}
{{- partial "opengraph.html" . -}}
{{- template "_internal/schema.html" . -}}
{{- template "_internal/twitter_cards.html" . -}}
{{- partialCached "head-css.html" . -}}
<!-- Google Analytics -->
{{- if and (eq hugo.Environment "production") .Site.Config.Services.GoogleAnalytics.ID }}
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin />
{{ partial "google-analytics.html" . }}
{{- end }}
<script>
/* Initialize light/dark mode */
const defaultTheme = '{{ site.Params.theme.default | default `system`}}';
const setDarkTheme = () => {
document.documentElement.classList.add("dark");
document.documentElement.style.colorScheme = "dark";
}
const setLightTheme = () => {
document.documentElement.classList.remove("dark");
document.documentElement.style.colorScheme = "light";
}
if ("color-theme" in localStorage) {
localStorage.getItem("color-theme") === "dark" ? setDarkTheme() : setLightTheme();
} else {
defaultTheme === "dark" ? setDarkTheme() : setLightTheme();
if (defaultTheme === "system") {
window.matchMedia("(prefers-color-scheme: dark)").matches ? setDarkTheme() : setLightTheme();
}
}
</script>
<!-- KaTeX-->
{{ $noop := .WordCount -}}
{{ if .Page.Store.Get "hasMath" -}}
<!-- TODO: make url configurable -->
{{ $katexCssUrl := printf "https://cdn.jsdelivr.net/npm/katex@latest/dist/katex%s.css" (cond hugo.IsProduction ".min" "") -}}
{{ with try (resources.GetRemote $katexCssUrl) -}}
{{ with .Err -}}
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
{{ else with.Value -}}
{{ with resources.Copy (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) . -}}
<link rel="stylesheet" href="{{- .RelPermalink -}}" integrity="{{- . | fingerprint -}}" crossorigin="anonymous" />
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ partial "custom/head-end.html" . -}}
</head>