Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
Set default theme in config toml
Browse files Browse the repository at this point in the history
  • Loading branch information
panr committed Dec 21, 2018
1 parent 1974d30 commit 9532cb8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ paginate = 5

[params]
subtitle = "A simple theme for Hugo"
# "light" or "dark"
defaultTheme = "dark"

[params.logo]
logoText = "hello friend"
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{ end }}
{{ partial "head.html" . }}
</head>
<body class="dark-theme">
<body class="{{ if ne $.Site.Params.defaultTheme "light" -}} dark-theme {{- end -}}">
<div class="container">
{{ partial "header.html" . }}

Expand Down
22 changes: 12 additions & 10 deletions source/js/theme.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Toggle theme

const getTheme = window.localStorage && window.localStorage.getItem('theme')
const themeToggle = document.querySelector('.theme-toggle')
const isDark = getTheme === 'dark' || getTheme === null
const getTheme = window.localStorage && window.localStorage.getItem("theme");
const themeToggle = document.querySelector(".theme-toggle");
const isDark = getTheme === "dark";

document.body.classList.toggle('dark-theme', isDark)
if (getTheme !== null) {
document.body.classList.toggle("dark-theme", isDark);
}

themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-theme')
themeToggle.addEventListener("click", () => {
document.body.classList.toggle("dark-theme");
window.localStorage &&
window.localStorage.setItem(
'theme',
document.body.classList.contains('dark-theme') ? 'dark' : 'light',
)
})
"theme",
document.body.classList.contains("dark-theme") ? "dark" : "light",
);
});

0 comments on commit 9532cb8

Please sign in to comment.