update blog theme

This commit is contained in:
pacientes
2020-11-28 13:39:50 +00:00
3 changed files with 25 additions and 32 deletions

View File

@@ -64,11 +64,5 @@
}
})
</script>
{{- else -}}
{{/* case where owner disables theme button after deployment, this resets the stored theme */}}
<script>
localStorage.removeItem("pref-theme");
</script>
{{- end }}

View File

@@ -1,26 +1,23 @@
{{- /* theme-toggle is enabled */}}
{{- if (not .Site.Params.disableThemeToggle) }}
{{- /* theme is light */}}
{{- if (eq .Site.Params.defaultTheme "light") }}
<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 {
document.body.classList.remove('dark')
}
</script>
{{- /* theme is dark */}}
{{- else if (eq .Site.Params.defaultTheme "dark") }}
<script>
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
} else if (localStorage.getItem("pref-theme") === "light") {
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) ) }}
{{- else }}
{{- /* theme is auto */}}
<script>
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
@@ -30,6 +27,15 @@
document.body.classList.add('dark');
}
</script>
{{- end }}
{{- /* theme-toggle is disabled and theme is auto */}}
{{- else if (and (ne .Site.Params.defaultTheme "light") (ne .Site.Params.defaultTheme "dark"))}}
<script>
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
}
</script>
{{- end }}
<noscript>