Added themes
This commit is contained in:
parent
076a4ec391
commit
627f1f5d32
12 changed files with 213 additions and 108 deletions
|
@ -2,6 +2,13 @@
|
|||
<nav>
|
||||
<ul>
|
||||
<li class="nav-menu-title{{if .IsHome}} nav-menu-active{{end}}"><a href="/">{{ .Site.Title }}</a></li>
|
||||
<li>
|
||||
<select id="themes" class="nav-menu-magin-left" onchange="setTheme()">
|
||||
<option value="black-theme">Black</option>
|
||||
<option value="dark-theme">Dark</option>
|
||||
<option value="light-theme">Light</option>
|
||||
</select>
|
||||
</li>
|
||||
{{- $p := . -}}
|
||||
|
||||
{{- range first 1 .Site.Menus.main.ByWeight -}}
|
||||
|
|
14
layouts/partials/themeSwitcher.html
Normal file
14
layouts/partials/themeSwitcher.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<script>
|
||||
function setTheme() {
|
||||
const themeName = document.getElementById('themes').value;
|
||||
localStorage.setItem('theme', themeName);
|
||||
document.documentElement.className = themeName;
|
||||
}
|
||||
(function () { // Set the theme on page load
|
||||
const themeName = localStorage.getItem('theme');
|
||||
if (themeName) {
|
||||
document.documentElement.className = themeName;
|
||||
document.getElementById('themes').value = themeName;
|
||||
}
|
||||
})();
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue