summaryrefslogtreecommitdiff
path: root/layouts/partials/header.html
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/partials/header.html')
-rw-r--r--layouts/partials/header.html29
1 files changed, 20 insertions, 9 deletions
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index 233587b..0a433b9 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -1,21 +1,32 @@
-{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
+{{- if (eq .Site.Params.defaultTheme "light") }}
<script>
- // load memory
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
} else if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
} else {
- if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
- document.body.classList.add('dark');
- }
+ document.body.classList.remove('dark')
}
</script>
-{{- end }}
-{{- if (and (.Site.Params.disableThemeToggle) (eq .Site.Params.defaultTheme "auto")) }}
+{{- else if (eq .Site.Params.defaultTheme "dark") }}
<script>
- if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ if (localStorage.getItem("pref-theme") === "dark") {
+ document.body.classList.add('dark');
+ } else if (localStorage.getItem("pref-theme") === "light") {
+ document.body.classList.remove('dark')
+ } else {
+ document.body.classList.add('dark');
+ }
+
+</script>
+{{- else if (or (eq .Site.Params.defaultTheme "auto") (not .Site.Params.disableThemeToggle) ) }}
+<script>
+ if (localStorage.getItem("pref-theme") === "dark") {
+ document.body.classList.add('dark');
+ } else if (localStorage.getItem("pref-theme") === "light") {
+ document.body.classList.remove('dark')
+ } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
}
@@ -41,7 +52,7 @@
{{- .Site.Params.label.text | default .Site.Title -}}
</a>
<span class="logo-switches">
- {{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
+ {{- if (not .Site.Params.disableThemeToggle) }}
<span class="theme-toggle">
<a id="theme-toggle" accesskey="t">
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"