authors now can pick a default theme color

This commit is contained in:
Mivinci 2022-01-26 20:39:49 +08:00
parent 577b74f612
commit d4d30a0c35
3 changed files with 22 additions and 8 deletions

View file

@ -1,29 +1,28 @@
const light = '{{ index .Site.Params.switch 1 }}'
const dark = '{{ index .Site.Params.switch 0 }}'
const icon_light = '{{ index .Site.Params.switch 1 }}'
const icon_dark = '{{ index .Site.Params.switch 0 }}'
const comment = '{{ .Site.Params.comment }}'
const LIGHT = 'light', DARK = 'dark'
const light = 'light', dark = 'dark'
const themeSwitcher = document.getElementById('theme-switcher')
// set switcher
themeSwitcher.innerHTML = localStorage.theme === LIGHT ? light : dark
themeSwitcher.innerHTML = localStorage.theme === light ? icon_light : icon_dark
themeSwitcher.addEventListener('click', function () {
const currentTheme = localStorage.theme
const newTheme = currentTheme === LIGHT ? DARK : LIGHT
const newTheme = currentTheme === light ? dark : light
// switch global theme
switchMinimaTheme(currentTheme, newTheme)
// switch utterance theme if necessary
if (comment === 'utterances')
switchUtteranceTheme(`github-${newTheme}`)
});
function switchMinimaTheme(oldTheme, newTheme) {
const { classList } = document.documentElement
const text = newTheme === LIGHT ? light : dark;
const text = newTheme === light ? icon_light : icon_dark;
classList.remove(oldTheme);
classList.add(newTheme);