Skip to content

Commit

Permalink
Add dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
32th-System committed Mar 26, 2023
1 parent d908264 commit 19f83dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
37 changes: 29 additions & 8 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@

<header>
<a href="/" class="home-link">{{ site_info.title }}</a>

<nav>
<ul class="nav">
{%- for entry in collections.all | eleventyNavigation %}
<li class="nav-item"><a href="{{ entry.url }}"{% if entry.url == page.url %} aria-current="page"{% endif %}>{{ entry.title }}</a></li>
{%- endfor %}
</ul>
</nav>
<a style="margin-left: auto; margin-right: 20px;" onclick="toggleTheme()">🌙</a>
</header>

<main>
Expand All @@ -33,3 +26,31 @@

<footer></footer>
</body>

<script>
document.body.classList.remove("theme-light");
const themes = [ "theme-light", "theme-dark" ];
let theme = localStorage.getItem("theme");
if(!themes.includes(theme)) {
theme = "theme-light";
localStorage.setItem("theme", theme);
}
document.body.classList.add(theme);
const toggleTheme = () => {
document.body.classList.remove(theme)
switch(theme) {
case "theme-light":
theme = "theme-dark";
break;
case "theme-dark": default:
theme = "theme-light"
break;
}
document.body.classList.add(theme);
localStorage.setItem("theme", theme);
}
</script>
8 changes: 8 additions & 0 deletions content/main.sass
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ main
.post-metadata
font: 400 14px "Lato", "Arial", sans-serif
color: grey

.theme-light
color: black
background-color: white

.theme-dark
color: white
background-color: #101010

0 comments on commit 19f83dc

Please sign in to comment.