docs: persist color themes (#18102)

This commit is contained in:
dopamine 2024-08-31 08:01:36 +08:00 committed by GitHub
parent 4246d1e468
commit 3b4acab759
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1 additions and 17 deletions

View File

@ -152,9 +152,3 @@ gtag('config', 'UA-175337989-1');`,
`, `,
], ],
] ]
head.push([
'script',
{},
fs.readFileSync(path.resolve(vpRoot, 'dark-mode.js'), 'utf-8'),
])

View File

@ -1,10 +0,0 @@
;(() => {
const saved = localStorage.getItem('el-theme-appearance')
if (
saved === 'auto'
? window.matchMedia(`(prefers-color-scheme: dark)`).matches
: saved === 'dark'
) {
document.documentElement.classList.add('dark')
}
})()

View File

@ -1,7 +1,7 @@
import { useDark, useToggle } from '@vueuse/core' import { useDark, useToggle } from '@vueuse/core'
export const isDark = useDark({ export const isDark = useDark({
storageKey: 'el-theme-appearance', storageKey: 'vitepress-theme-appearance',
}) })
export const toggleDark = useToggle(isDark) export const toggleDark = useToggle(isDark)