mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +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 SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
|
||||||
color: {
|
color: {
|
||||||
// default theme mode
|
// default theme mode
|
||||||
mode: 'light', // light, dark
|
mode: 'light', // light, dark, auto
|
||||||
light: {
|
light: {
|
||||||
// primary color
|
// primary color
|
||||||
// used for title, hover, etc
|
// used for title, hover, etc
|
||||||
|
|
|
@ -25,7 +25,7 @@ site: {
|
||||||
// site description
|
// site description
|
||||||
description: 'Retypeset is a static blog theme...'
|
description: 'Retypeset is a static blog theme...'
|
||||||
// use i18n title/subtitle/description from src/i18n/ui.ts instead of static ones above
|
// 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 name
|
||||||
author: 'radishzz'
|
author: 'radishzz'
|
||||||
// site url
|
// site url
|
||||||
|
|
|
@ -25,7 +25,7 @@ site: {
|
||||||
// descripción del sitio
|
// descripción del sitio
|
||||||
description: 'Retypeset is a static blog theme...'
|
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
|
// 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
|
// nombre del autor
|
||||||
author: 'radishzz'
|
author: 'radishzz'
|
||||||
// url del sitio
|
// url del sitio
|
||||||
|
|
|
@ -25,7 +25,7 @@ site: {
|
||||||
// サイト説明
|
// サイト説明
|
||||||
description: 'Retypeset is a static blog theme...'
|
description: 'Retypeset is a static blog theme...'
|
||||||
// 上記の静的設定の代わりに src/i18n/ui.ts の多言語タイトル/サブタイトル/説明を使用
|
// 上記の静的設定の代わりに src/i18n/ui.ts の多言語タイトル/サブタイトル/説明を使用
|
||||||
i18nTitle: true // true, false
|
i18nTitle: true // light, dark, auto
|
||||||
// 著者名
|
// 著者名
|
||||||
author: 'radishzz'
|
author: 'radishzz'
|
||||||
// サイトURL
|
// サイトURL
|
||||||
|
|
|
@ -41,7 +41,7 @@ site: {
|
||||||
```ts
|
```ts
|
||||||
color: {
|
color: {
|
||||||
// режим темы по умолчанию
|
// режим темы по умолчанию
|
||||||
mode: 'light' // light, dark
|
mode: 'light' // light, dark, auto
|
||||||
// светлый режим
|
// светлый режим
|
||||||
light: {
|
light: {
|
||||||
// основной цвет
|
// основной цвет
|
||||||
|
|
|
@ -41,7 +41,7 @@ site: {
|
||||||
```ts
|
```ts
|
||||||
color: {
|
color: {
|
||||||
// 默認主題
|
// 默認主題
|
||||||
mode: 'light' // light, dark
|
mode: 'light' // light, dark, auto
|
||||||
// 亮色模式
|
// 亮色模式
|
||||||
light: {
|
light: {
|
||||||
// 高亮顏色
|
// 高亮顏色
|
||||||
|
|
|
@ -41,7 +41,7 @@ site: {
|
||||||
```ts
|
```ts
|
||||||
color: {
|
color: {
|
||||||
// 默认主题
|
// 默认主题
|
||||||
mode: 'light' // light, dark
|
mode: 'light' // light, dark, auto
|
||||||
// 亮色模式
|
// 亮色模式
|
||||||
light: {
|
light: {
|
||||||
// 高亮颜色
|
// 高亮颜色
|
||||||
|
|
|
@ -110,8 +110,11 @@ function isCurrentDark() {
|
||||||
const currentTheme = localStorage.getItem('theme')
|
const currentTheme = localStorage.getItem('theme')
|
||||||
if (currentTheme)
|
if (currentTheme)
|
||||||
return currentTheme === 'dark'
|
return currentTheme === 'dark'
|
||||||
if (defaultMode)
|
if (defaultMode === 'light')
|
||||||
return defaultMode === 'dark'
|
return false
|
||||||
|
if (defaultMode === 'dark')
|
||||||
|
return true
|
||||||
|
// Auto mode or undefined, use system preference
|
||||||
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
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: {
|
color: {
|
||||||
mode: 'light' | 'dark'
|
mode: 'light' | 'dark' | 'auto'
|
||||||
light: {
|
light: {
|
||||||
primary: string
|
primary: string
|
||||||
secondary: string
|
secondary: string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue