diff --git a/README.md b/README.md index 34b0011..de2d0e6 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Forked from [Ezhil Theme](https://github.com/vividvilla/ezhil) - Callouts - Tags - Auto Dark Mode(based on system theme) +- Dark/Light Mode toggle - tl:dr; frontamatter - Cache busting for CSS files @@ -75,7 +76,7 @@ pygmentscodefencesguesssyntax = true paginate=3 # articles per page [params] - mode="auto" # color-mode → light,dark or auto + mode="auto" # color-mode → light,dark,toggle or auto useCDN=false # don't use CDNs for fonts and icons, instead serve them locally. subtitle = "Minimal and Clean [blog theme for Hugo](https://github.com/athul/archie)" diff --git a/layouts/partials/head.html b/layouts/partials/head.html index ab3f39d..e8a637a 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -6,5 +6,9 @@ {{ range .Site.Menus.main }} {{ .Name }} {{ end }} + {{ if eq .Site.Params.mode "toggle" -}} + | + + {{ end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index c5ae589..98ab662 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -39,9 +39,9 @@ {{ $style := resources.Get "css/main.css" | fingerprint }} - {{- if or (eq .Site.Params.mode "auto") (eq .Site.Params.mode "dark") -}} + {{- if or (eq .Site.Params.mode "auto") (eq .Site.Params.mode "dark") (eq .Site.Params.mode "toggle") -}} {{ $darkstyle := resources.Get "css/dark.css" | fingerprint }} - + {{ end }} diff --git a/static/js/themetoggle.js b/static/js/themetoggle.js new file mode 100644 index 0000000..f8c6dcd --- /dev/null +++ b/static/js/themetoggle.js @@ -0,0 +1,23 @@ +function setTheme(mode) { + localStorage.setItem("theme-storage", mode); + if (mode === "dark") { + document.getElementById("darkModeStyle").disabled=false; + document.getElementById("dark-mode-toggle").innerHTML = ""; + feather.replace() + } else if (mode === "light") { + document.getElementById("darkModeStyle").disabled=true; + document.getElementById("dark-mode-toggle").innerHTML = ""; + feather.replace() + } +} + +function toggleTheme() { + if (localStorage.getItem("theme-storage") === "light") { + setTheme("dark"); + } else if (localStorage.getItem("theme-storage") === "dark") { + setTheme("light"); + } +} + +var savedTheme = localStorage.getItem("theme-storage") || "light"; +setTheme(savedTheme);