mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-08 23:16:54 +00:00
部分参数配置化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import cookie from 'react-cookies'
|
||||
import BLOG from '@/blog.config'
|
||||
import { getQueryParam, getQueryVariable } from '../lib/utils'
|
||||
import { getQueryParam, getQueryVariable, isBrowser } from '../lib/utils'
|
||||
import dynamic from 'next/dynamic'
|
||||
import getConfig from 'next/config'
|
||||
import * as ThemeComponents from '@theme-components'
|
||||
@@ -15,13 +15,38 @@ export const { THEMES = [] } = getConfig().publicRuntimeConfig
|
||||
export const getLayoutByTheme = ({ router, theme }) => {
|
||||
const themeQuery = getQueryParam(router.asPath, 'theme') || theme
|
||||
const layoutName = getLayoutNameByPath(router.pathname)
|
||||
|
||||
if (themeQuery !== BLOG.THEME) {
|
||||
return dynamic(() => import(`@/themes/${themeQuery}`).then(m => m[layoutName]), { ssr: true })
|
||||
return dynamic(() => import(`@/themes/${themeQuery}`).then(m => {
|
||||
setTimeout(() => {
|
||||
checkThemeDOM()
|
||||
}, 500);
|
||||
return m[layoutName]
|
||||
}), { ssr: true })
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
checkThemeDOM()
|
||||
}, 100);
|
||||
return ThemeComponents[layoutName]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换主题时的特殊处理
|
||||
*/
|
||||
const checkThemeDOM = () => {
|
||||
if (isBrowser) {
|
||||
const elements = document.querySelectorAll('[id^="theme-"]')
|
||||
if (elements?.length > 1) {
|
||||
elements[elements.length - 1].scrollIntoView()
|
||||
// 删除前面的元素,只保留最后一个元素
|
||||
for (let i = 0; i < elements.length - 1; i++) {
|
||||
elements[i].parentNode.removeChild(elements[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路径 获取对应的layout
|
||||
* @param {*} path
|
||||
|
||||
Reference in New Issue
Block a user