mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-01 15:10:14 +00:00
Merge branch 'main' into original-main-fix-DOMException
This commit is contained in:
@@ -7,6 +7,20 @@ import { getQueryParam, getQueryVariable, isBrowser } from '../lib/utils'
|
||||
// 在next.config.js中扫描所有主题
|
||||
export const { THEMES = [] } = getConfig().publicRuntimeConfig
|
||||
|
||||
/**
|
||||
* 获取主体配置
|
||||
*/
|
||||
export const getThemeConfig = async themeQuery => {
|
||||
if (themeQuery && themeQuery !== BLOG.THEME) {
|
||||
const THEME_CONFIG = await import(`@/themes/${themeQuery}`).then(
|
||||
m => m.THEME_CONFIG
|
||||
)
|
||||
return THEME_CONFIG
|
||||
} else {
|
||||
return ThemeComponents?.THEME_CONFIG
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载全局布局
|
||||
* @param {*} themeQuery
|
||||
@@ -14,7 +28,11 @@ export const { THEMES = [] } = getConfig().publicRuntimeConfig
|
||||
*/
|
||||
export const getGlobalLayoutByTheme = themeQuery => {
|
||||
if (themeQuery !== BLOG.THEME) {
|
||||
return dynamic(() => import(`@/themes/${themeQuery}`).then(m => m[getLayoutNameByPath(-1)]), { ssr: true })
|
||||
return dynamic(
|
||||
() =>
|
||||
import(`@/themes/${themeQuery}`).then(m => m[getLayoutNameByPath(-1)]),
|
||||
{ ssr: true }
|
||||
)
|
||||
} else {
|
||||
return ThemeComponents[getLayoutNameByPath('-1')]
|
||||
}
|
||||
@@ -36,7 +54,8 @@ export const getLayoutByTheme = ({ router, theme }) => {
|
||||
checkThemeDOM()
|
||||
}, 500)
|
||||
|
||||
const components = m[getLayoutNameByPath(router.pathname, router.asPath)]
|
||||
const components =
|
||||
m[getLayoutNameByPath(router.pathname, router.asPath)]
|
||||
if (components) {
|
||||
return components
|
||||
} else {
|
||||
@@ -49,7 +68,8 @@ export const getLayoutByTheme = ({ router, theme }) => {
|
||||
setTimeout(() => {
|
||||
checkThemeDOM()
|
||||
}, 100)
|
||||
const components = ThemeComponents[getLayoutNameByPath(router.pathname, router.asPath)]
|
||||
const components =
|
||||
ThemeComponents[getLayoutNameByPath(router.pathname, router.asPath)]
|
||||
if (components) {
|
||||
return components
|
||||
} else {
|
||||
@@ -104,6 +124,7 @@ export const initDarkMode = (updateDarkMode, defaultDarkMode) => {
|
||||
const userDarkMode = loadDarkModeFromLocalStorage()
|
||||
if (userDarkMode) {
|
||||
newDarkMode = userDarkMode === 'dark' || userDarkMode === 'true'
|
||||
saveDarkModeToLocalStorage(newDarkMode) // 用户手动的才保存
|
||||
}
|
||||
|
||||
// 如果站点强制设置默认深色,则优先级改过用
|
||||
@@ -118,8 +139,9 @@ export const initDarkMode = (updateDarkMode, defaultDarkMode) => {
|
||||
}
|
||||
|
||||
updateDarkMode(newDarkMode)
|
||||
saveDarkModeToLocalStorage(newDarkMode)
|
||||
document.getElementsByTagName('html')[0].setAttribute('class', newDarkMode ? 'dark' : 'light')
|
||||
document
|
||||
.getElementsByTagName('html')[0]
|
||||
.setAttribute('class', newDarkMode ? 'dark' : 'light')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,11 +155,14 @@ export function isPreferDark() {
|
||||
if (BLOG.APPEARANCE === 'auto') {
|
||||
// 系统深色模式或时间是夜间时,强行置为夜间模式
|
||||
const date = new Date()
|
||||
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
const prefersDarkMode = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)'
|
||||
).matches
|
||||
return (
|
||||
prefersDarkMode ||
|
||||
(BLOG.APPEARANCE_DARK_TIME &&
|
||||
(date.getHours() >= BLOG.APPEARANCE_DARK_TIME[0] || date.getHours() < BLOG.APPEARANCE_DARK_TIME[1]))
|
||||
(date.getHours() >= BLOG.APPEARANCE_DARK_TIME[0] ||
|
||||
date.getHours() < BLOG.APPEARANCE_DARK_TIME[1]))
|
||||
)
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user