mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 03:32:51 +02:00
fix: theme toggle error
This commit is contained in:
parent
9d47579a87
commit
a8c56b6e8a
1 changed files with 0 additions and 17 deletions
|
@ -20,23 +20,6 @@
|
||||||
document.startViewTransition(switchTheme)
|
document.startViewTransition(switchTheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply theme to document
|
|
||||||
function applyTheme(doc: Document) {
|
|
||||||
const theme = localStorage.getItem('theme')
|
|
||||||
const isDark = theme === 'dark'
|
|
||||||
doc.documentElement.classList.toggle('dark', isDark)
|
|
||||||
const button = doc === document ? themeToggle : doc.querySelector('button[aria-pressed]')
|
|
||||||
if (button) {
|
|
||||||
button.setAttribute('aria-pressed', String(isDark))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize theme and handle page navigation
|
|
||||||
applyTheme(document)
|
|
||||||
document.addEventListener('astro:before-swap', (e) => {
|
|
||||||
applyTheme(e.newDocument)
|
|
||||||
})
|
|
||||||
|
|
||||||
themeToggle.addEventListener('click', toggleTheme)
|
themeToggle.addEventListener('click', toggleTheme)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue