diff --git a/README.md b/README.md index 4cabfb0..52766e4 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,14 @@ npm install astro-theme-toggle + diff --git a/lib/theme-script.ts b/lib/theme-script.ts index 7f2db44..4e6a535 100644 --- a/lib/theme-script.ts +++ b/lib/theme-script.ts @@ -37,8 +37,15 @@ setStyle(theme) } + function setupTheme() { + setTheme(getTheme()) + } + // Set the theme on load - setTheme(getTheme()) + setupTheme() + + // Set the theme after a page swap + document.addEventListener('astro:after-swap', setupTheme) window.astroThemeToggle = { setTheme, getTheme } })() diff --git a/lib/theme-style.astro b/lib/theme-style.astro deleted file mode 100644 index 2a7806f..0000000 --- a/lib/theme-style.astro +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/website/components/head.astro b/website/components/head.astro index 56646f5..1f00e04 100644 --- a/website/components/head.astro +++ b/website/components/head.astro @@ -1,5 +1,6 @@ --- import { ThemeScript } from 'astro-theme-toggle' +import { ViewTransitions } from 'astro:transitions' --- @@ -7,5 +8,6 @@ import { ThemeScript } from 'astro-theme-toggle' + diff --git a/website/components/theme-toggle-button.astro b/website/components/theme-toggle-button.astro index 3605bbf..4d8fc9f 100644 --- a/website/components/theme-toggle-button.astro +++ b/website/components/theme-toggle-button.astro @@ -11,7 +11,11 @@ import IconMoonSvg from './icon-moon-svg.astro'