mirror of
https://github.com/imfing/hextra.git
synced 2025-08-24 18:06:35 -04:00
fix(theme-toggle): quick flash (light/dark) (#768)
* fix(theme-toggle): quick flash (light/dark) * chore: simplify * chore: simplify * chore: simplify
This commit is contained in:

committed by
GitHub

parent
18a9335d4b
commit
201ce3f763
@@ -59,6 +59,24 @@
|
||||
{{ partial "google-analytics.html" . -}}
|
||||
{{- end }}
|
||||
|
||||
<script>
|
||||
// The section must not be in the theme.js file because it can create a quick flash (switch between light and dark).
|
||||
|
||||
function setTheme(theme) {
|
||||
document.documentElement.classList.remove("light", "dark");
|
||||
|
||||
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>
|
||||
|
||||
<!-- Math engine -->
|
||||
{{ $noop := .WordCount -}}
|
||||
{{- $engine := site.Params.math.engine | default "katex" -}}
|
||||
|
Reference in New Issue
Block a user