summaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-10-05 14:33:48 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-10-05 14:34:44 +0530
commita9e00a3640b5d98e6fce03dc5c67e87e3fac916d (patch)
tree2ebd32d7d9c35a4f98691a99fb36eac0906be0a4 /layouts
parent994c0b56e198f48c20f7780d4e6e52adf4baa153 (diff)
theme: set proper conditions
for having default-theme with theme-toggle * can set/unset default theme * for default-theme: dark/light : theme-toggle will not be visible * theme-toggle with defaultheme: auto is functional fixes #25 for #15
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/footer.html4
-rw-r--r--layouts/partials/header.html11
2 files changed, 11 insertions, 4 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index d7e9166..1c28f3a 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -49,7 +49,7 @@
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
}
</script>
-{{- if not .Site.Params.disableThemeToggle }}
+{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
<script>
document.getElementById("theme-toggle").addEventListener("click", () => {
if (document.body.className.includes("dark")) {
@@ -66,4 +66,4 @@
<script>
localStorage.removeItem("pref-theme");
</script>
-{{- end }}
+{{- end }} \ No newline at end of file
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index f67f33b..40e7b15 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -1,4 +1,4 @@
-{{- if eq .Site.Params.defaultTheme "auto" }}
+{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
<script>
// load memory
if (localStorage.getItem("pref-theme") === "dark") {
@@ -12,6 +12,13 @@
}
</script>
{{- end }}
+{{- if (and (.Site.Params.disableThemeToggle) (eq .Site.Params.defaultTheme "auto")) }}
+<script>
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ document.body.classList.add('dark');
+ }
+</script>
+{{- end }}
<noscript>
<style type="text/css">
.theme-toggle,
@@ -24,7 +31,7 @@
<nav class="nav">
<p class="logo">
<a href="{{ "" | absLangURL }}">{{ .Site.Title }}</a>
- {{- if not .Site.Params.disableThemeToggle }}
+ {{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
<span class="theme-toggle">
<a id="theme-toggle">
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"