diff --git a/Makefile b/Makefile index aa57ef8..133fbf4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ TEMPLATE := templates OUTPUT := output CONTENT := content TPL := $(wildcard $(TEMPLATE)/*.css) \ - $(shell find templates -name "*.html") + $(shell find templates -name "*.html") \ + $(shell find templates -name "*.js") TPL_OUT := $(patsubst $(TEMPLATE)%, $(OUTPUT)%, $(TPL)) STATIC := $(wildcard $(TEMPLATE)/*.png) \ $(wildcard $(TEMPLATE)/*.webp) \ @@ -20,6 +21,9 @@ $(OUTPUT)/%.html: beeceej.com $(TPL) $(OUTPUT)/%.css: beeceej.com $(TPL) $(TEMPLATIZE) $@ +$(OUTPUT)/%.js: beeceej.com $(TPL) + $(TEMPLATIZE) $@ + $(OUTPUT)/%.png: beeceej.com $(STATIC) cp $(TEMPLATE)/$(notdir $@) $@ diff --git a/templates/common.css b/templates/common.css index 36a39c7..a5a400f 100644 --- a/templates/common.css +++ b/templates/common.css @@ -1,10 +1,17 @@ {{define "common_css"}} + body { + --link-text-color: grey; + --background-color: black; + font-size: 24px; font-family: monospace; text-align: center; margin: 0 auto; width: 80%; + + background: var(--background-color) + } @media only screen and (max-width: 600px) { body { @@ -14,9 +21,8 @@ body { } a { - link-decoration: none; text-decoration: none; - color: #02071f; + color: var(--link-text-color); } a:hover { diff --git a/templates/common.js b/templates/common.js new file mode 100644 index 0000000..e6699c4 --- /dev/null +++ b/templates/common.js @@ -0,0 +1,46 @@ +{{define "common-js"}} + +const cssMappings = { + dark: { + "--link-text-color": "grey", + "--background-color": "black", + }, + light: { + "--link-text-color": "#02071f", + "--background-color": "white", + }, +}; + +const root = document.querySelector(":root"); + +function updateColors() { + if (JSON.parse(window.localStorage.getItem("dark-mode-enabled"))) { + Object.entries(cssMappings["dark"]).forEach(([key, value]) => { + document.body.style.setProperty(key, value); + }); + return; + } + Object.entries(cssMappings["light"]).forEach(([key, value]) => { + document.body.style.setProperty(key, value); + }); +} + +function toggleDarkMode(event) { + const darkModeEnabled = window.localStorage.getItem("dark-mode-enabled"); + if (darkModeEnabled === "null") { + window.localStorage.setItem("dark-mode-enabled", "true"); + return; + } + window.localStorage.setItem( + "dark-mode-enabled", + !JSON.parse(window.localStorage.getItem("dark-mode-enabled")), + ); + updateColors(); +} + +updateColors(); + +document + .getElementById("dark-mode-toggle-button") + .addEventListener("click", toggleDarkMode); +{{end}} diff --git a/templates/footer.html b/templates/footer.html index 8f24e8d..58e8c91 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,5 +1,7 @@ {{ define "footer" }} {{ end }} diff --git a/templates/index.html b/templates/index.html index 0f83879..caa3f30 100644 --- a/templates/index.html +++ b/templates/index.html @@ -33,6 +33,9 @@ {{end}} {{- template "footer" . -}} + {{end}} {{- template "index" . -}} diff --git a/templates/nav.css b/templates/nav.css index 1f6ded5..8443e97 100644 --- a/templates/nav.css +++ b/templates/nav.css @@ -8,12 +8,13 @@ nav { top: 0; margin-bottom: 10px; /*Push content pages down a bit */ border-bottom: solid grey; - background-color: white; + background-color: var(--background-color); + } /* Styles for the Nav Items */ #nav-list { text-transform: uppercase; - color: grey; + color: var(--link-text-color); } {{end}} diff --git a/templates/nav.html b/templates/nav.html index f6971b7..9dff9e7 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -1,5 +1,5 @@ {{define "nav"}} -