summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-11-03 20:05:21 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-11-03 20:07:59 +0530
commit0eed773e6dcf999cb052b6f781bfbe7ad74e63c7 (patch)
tree21f623ef7f628df5c1049490c8813cd6cee787ee
parent229df19ec9b535ea1ec3403c01e1e7db287c5d0d (diff)
theme-switch-button: improve logic
- owner can set dark/light/auto default theme - theme toggle will be enabled on all theme modes unless disbaled - if disableThemeToggle is true, user won't be able to switch themes, here auto (a/c to system theme) also works for #69
-rw-r--r--layouts/partials/footer.html2
-rw-r--r--layouts/partials/header.html6
2 files changed, 4 insertions, 4 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index f3baf82..dbc4989 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -50,7 +50,7 @@
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
}
</script>
-{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
+{{- if (and (not .Site.Params.disableThemeToggle) (not (eq .Site.Params.defaultTheme "auto"))) }}
<script>
document.getElementById("theme-toggle").addEventListener("click", () => {
if (document.body.className.includes("dark")) {
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index 233587b..2dc56a6 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -1,4 +1,4 @@
-{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
+{{- if (and (not .Site.Params.disableThemeToggle) (not (eq .Site.Params.defaultTheme "auto"))) }}
<script>
// load memory
if (localStorage.getItem("pref-theme") === "dark") {
@@ -13,7 +13,7 @@
</script>
{{- end }}
-{{- if (and (.Site.Params.disableThemeToggle) (eq .Site.Params.defaultTheme "auto")) }}
+{{- if (eq .Site.Params.defaultTheme "auto") }}
<script>
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
@@ -41,7 +41,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"