mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-15 11:12:54 +02:00
Optimize the logic for switching between light and dark modes
This commit is contained in:
parent
abdcd76a80
commit
88a3a9f46b
9 changed files with 13 additions and 10 deletions
|
@ -24,7 +24,7 @@ export const themeConfig: ThemeConfig = {
|
|||
// COLOR SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
|
||||
color: {
|
||||
// default theme mode
|
||||
mode: 'light', // light, dark
|
||||
mode: 'light', // light, dark, auto
|
||||
light: {
|
||||
// primary color
|
||||
// used for title, hover, etc
|
||||
|
|
|
@ -25,7 +25,7 @@ site: {
|
|||
// site description
|
||||
description: 'Retypeset is a static blog theme...'
|
||||
// use i18n title/subtitle/description from src/i18n/ui.ts instead of static ones above
|
||||
i18nTitle: true // true, false
|
||||
i18nTitle: true // light, dark, auto
|
||||
// author name
|
||||
author: 'radishzz'
|
||||
// site url
|
||||
|
|
|
@ -25,7 +25,7 @@ site: {
|
|||
// descripción del sitio
|
||||
description: 'Retypeset is a static blog theme...'
|
||||
// usar título/subtítulo/descripción en varios idiomas desde src/i18n/ui.ts en lugar de los estáticos anteriores
|
||||
i18nTitle: true // true, false
|
||||
i18nTitle: true // light, dark, auto
|
||||
// nombre del autor
|
||||
author: 'radishzz'
|
||||
// url del sitio
|
||||
|
|
|
@ -25,7 +25,7 @@ site: {
|
|||
// サイト説明
|
||||
description: 'Retypeset is a static blog theme...'
|
||||
// 上記の静的設定の代わりに src/i18n/ui.ts の多言語タイトル/サブタイトル/説明を使用
|
||||
i18nTitle: true // true, false
|
||||
i18nTitle: true // light, dark, auto
|
||||
// 著者名
|
||||
author: 'radishzz'
|
||||
// サイトURL
|
||||
|
|
|
@ -41,7 +41,7 @@ site: {
|
|||
```ts
|
||||
color: {
|
||||
// режим темы по умолчанию
|
||||
mode: 'light' // light, dark
|
||||
mode: 'light' // light, dark, auto
|
||||
// светлый режим
|
||||
light: {
|
||||
// основной цвет
|
||||
|
|
|
@ -41,7 +41,7 @@ site: {
|
|||
```ts
|
||||
color: {
|
||||
// 默認主題
|
||||
mode: 'light' // light, dark
|
||||
mode: 'light' // light, dark, auto
|
||||
// 亮色模式
|
||||
light: {
|
||||
// 高亮顏色
|
||||
|
|
|
@ -41,7 +41,7 @@ site: {
|
|||
```ts
|
||||
color: {
|
||||
// 默认主题
|
||||
mode: 'light' // light, dark
|
||||
mode: 'light' // light, dark, auto
|
||||
// 亮色模式
|
||||
light: {
|
||||
// 高亮颜色
|
||||
|
|
|
@ -110,8 +110,11 @@ function isCurrentDark() {
|
|||
const currentTheme = localStorage.getItem('theme')
|
||||
if (currentTheme)
|
||||
return currentTheme === 'dark'
|
||||
if (defaultMode)
|
||||
return defaultMode === 'dark'
|
||||
if (defaultMode === 'light')
|
||||
return false
|
||||
if (defaultMode === 'dark')
|
||||
return true
|
||||
// Auto mode or undefined, use system preference
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
}
|
||||
|
||||
|
|
2
src/types/index.d.ts
vendored
2
src/types/index.d.ts
vendored
|
@ -15,7 +15,7 @@ export interface ThemeConfig {
|
|||
}
|
||||
|
||||
color: {
|
||||
mode: 'light' | 'dark'
|
||||
mode: 'light' | 'dark' | 'auto'
|
||||
light: {
|
||||
primary: string
|
||||
secondary: string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue