chore(scripts): generic way to build scripts (#829)

* chore: move core scripts

* chore: extract head scripts
This commit is contained in:
Ludovic Fernandez
2025-09-11 21:29:18 +02:00
committed by GitHub
parent ccb63d60f1
commit 1c06ae5580
17 changed files with 34 additions and 38 deletions

View File

@@ -55,32 +55,17 @@
{{ partial "components/analytics/analytics.html" . }}
<script>
// The section must not be in the theme.js file because it can create a quick flash (switch between light and dark).
{{- $scriptsHead := slice -}}
{{- range resources.Match "js/head/*.js" -}}
{{ $scriptsHead = $scriptsHead | append (resources.ExecuteAsTemplate .Name $ .) }}
{{- end -}}
function setTheme(theme) {
document.documentElement.classList.remove("light", "dark");
{{- $scripts := $scriptsHead | resources.Concat "js/main-head.js" -}}
if (theme !== "light" && theme !== "dark") {
theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
document.documentElement.classList.add(theme);
document.documentElement.style.colorScheme = theme;
}
setTheme("color-theme" in localStorage ? localStorage.getItem("color-theme") : '{{ site.Params.theme.default | default `system`}}')
</script>
<script>
// The section must not be in the banner.js file because it can create a quick flash.
if (localStorage.getItem('{{ site.Params.banner.key | default `banner-closed` }}')) {
document.documentElement.style.setProperty("--hextra-banner-height", "0px");
document.documentElement.classList.add("hextra-banner-hidden");
}
</script>
{{- if hugo.IsProduction -}}
{{- $scripts = $scripts | minify | fingerprint -}}
{{- end -}}
<script src="{{ $scripts.RelPermalink }}" integrity="{{ $scripts.Data.Integrity }}"></script>
<!-- Math engine -->
{{ $noop := .WordCount -}}