Skip to content

Commit

Permalink
Force dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
davegallant committed Apr 7, 2024
1 parent 190e0b2 commit f8d3133
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions themes/hugo-theme-gruvbox/assets/js/dark-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,13 @@ function setCommentsTheme(theme) {
}

function setTheme(theme) {
if (theme == "auto") {
theme = window.matchMedia("(prefers-color-scheme: light)").matches
? "light"
: "dark";
}
document.documentElement.setAttribute("data-theme", theme);
setPrismTheme(theme);
setCommentsTheme(theme);
}

function toggleTheme(e) {
const theme = e.currentTarget.classList.contains("light--hidden")
? "light"
: "dark";
setTheme(theme);
saveTheme(theme);
}

// Initial load
setTheme(getTheme());

window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (event) => {
setTheme(getTheme());
});
setTheme("dark");

// This script is inlined in the <head> of the document, so we have to wait
// for the DOM content before can add event listeners to the toggle buttons
Expand Down

0 comments on commit f8d3133

Please sign in to comment.