diff options
| author | Itay Cohen <itaycohen23@gmail.com> | 2020-11-04 10:34:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-04 14:04:45 +0530 |
| commit | 3064e8cfc5fa7e41e80ecdcd57f80276391c4a15 (patch) | |
| tree | 3882da18bb4dcccc4fe3f0070071c5d0dd16de0b /layouts/partials/header.html | |
| parent | 12b6b132e4c24c80813b726bd7191c83a5aead05 (diff) | |
theme-switch: Enable theme toggle unless specifically disabled (#69)
Co-authored-by: Aditya Telange <21258296+adityatelange@users.noreply.github.com>
Diffstat (limited to 'layouts/partials/header.html')
| -rw-r--r-- | layouts/partials/header.html | 29 |
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" |
