hugo-theme-minima/layouts/partials/head.html
2023-04-10 21:37:53 +08:00

48 lines
2.1 KiB
HTML

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{ template "_internal/google_analytics.html" . }}
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#ffffff">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#262d33">
<title>
{{ if .IsHome }}
{{ .Site.Title }} {{ if .Site.Params.subtitle }} - {{ .Site.Params.subtitle }} {{ end }}
{{ else }}
{{ .Site.Title }} - {{ .Title }}
{{ end }}
</title>
{{ $favicon := "favicon.ico" }}
<link rel="shortcut icon" href="{{ $favicon | relURL }}" type="image/x-icon" />
{{ $options := (dict "targetPath" "minima.css" "outputStyle" "compressed" "enableSourceMap" true) }}
{{ $style := resources.Get "css/main.scss" | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS $options }}
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
{{ $options = (dict "targetPath" "minima.js" "minify" true) }}
{{ $js := resources.Get "js/main.js" | js.Build $options | resources.ExecuteAsTemplate "minima.js" . }}
<script defer type="text/javascript" src="{{ $js.RelPermalink }}"></script>
{{ if .IsTranslated }}
{{ range .Translations }}
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}" title="{{ .Language.LanguageName }}">
{{ end }}
{{ end }}
</head>
<script>
// default to system color scheme.
const default_theme_config = '{{ .Site.Params.defaultTheme }}'
const default_light_theme = default_theme_config === 'system' ? 'light' : default_theme_config;
let default_theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : default_light_theme;
try {
const saved_theme = localStorage.getItem('theme')
if (saved_theme) {
default_theme = saved_theme === default_light_theme ? saved_theme : default_light_theme;
}
localStorage.setItem('theme', default_theme);
window.minima_theme = default_theme;
document.querySelector('html').classList.add(default_theme);
} catch (e) {
console.error(e);
}
</script>