feat/theme-switch

This commit is contained in:
tangly1024.com
2023-06-19 19:03:09 +08:00
parent 133fdd7c77
commit a042dc859a
28 changed files with 353 additions and 385 deletions

View File

@@ -1,7 +1,6 @@
import BLOG from '@/blog.config'
import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import { useGlobal } from '@/lib/global'
import { Suspense, useEffect, useState } from 'react'
import { idToUuid } from 'notion-utils'
import { useRouter } from 'next/router'
@@ -9,35 +8,16 @@ import { isBrowser } from '@/lib/utils'
import { getNotion } from '@/lib/notion/getNotion'
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
import md5 from 'js-md5'
import dynamic from 'next/dynamic'
import Loading from '@/components/Loading'
const layout = 'LayoutSlug'
/**
* 懒加载默认主题
*/
const DefaultLayout = dynamic(() => import(`@/themes/${BLOG.THEME}/${layout}`), { ssr: true })
/**
* 根据notion的slug访问页面
* @param {*} props
* @returns
*/
const Slug = props => {
const { theme, setOnLoading } = useGlobal()
const { post, siteInfo } = props
const { post, siteInfo, Layout } = props
const router = useRouter()
const [Layout, setLayout] = useState(DefaultLayout)
// 切换主题
useEffect(() => {
const loadLayout = async () => {
const newLayout = await dynamic(() => import(`@/themes/${theme}/${layout}`))
setLayout(newLayout)
}
loadLayout()
}, [theme])
// 文章锁🔐
const [lock, setLock] = useState(post?.password && post?.password !== '')
@@ -57,7 +37,6 @@ const Slug = props => {
// 文章加载
useEffect(() => {
setOnLoading(false)
// 404
if (!post) {
setTimeout(() => {