mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-22 15:09:43 +00:00
optimize init method
This commit is contained in:
16
lib/theme.js
16
lib/theme.js
@@ -1,7 +1,7 @@
|
||||
import cookie from 'react-cookies'
|
||||
import BLOG from '@/blog.config'
|
||||
import { ALL_THEME } from '@/themes'
|
||||
import { getQueryVariable } from './utils'
|
||||
import { isBrowser, getQueryVariable } from './utils'
|
||||
|
||||
/**
|
||||
* 初始化主题 , 优先级 query > cookies > systemPrefer
|
||||
@@ -27,14 +27,14 @@ export const initDarkMode = (isDarkMode, updateDarkMode) => {
|
||||
* @param {*} changeTheme
|
||||
*/
|
||||
export const initTheme = (theme, changeTheme) => {
|
||||
const queryTheme = getQueryVariable('theme')
|
||||
if (queryTheme && ALL_THEME.indexOf(queryTheme) > -1) {
|
||||
changeTheme(queryTheme)
|
||||
} else {
|
||||
const userTheme = loadThemeFromCookies()
|
||||
if (userTheme !== theme) {
|
||||
changeTheme(userTheme)
|
||||
if (isBrowser()) {
|
||||
const queryTheme = getQueryVariable('theme') || loadThemeFromCookies() || BLOG.THEME
|
||||
let currentTheme = theme
|
||||
if (queryTheme !== theme && ALL_THEME.indexOf(queryTheme) > -1) {
|
||||
currentTheme = queryTheme
|
||||
}
|
||||
changeTheme(currentTheme)
|
||||
saveThemeToCookies(currentTheme)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user