@@ -2,14 +2,15 @@ import BLOG from '@/blog.config'
2
2
import { getPostBlocks } from '@/lib/notion'
3
3
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
4
4
import { useGlobal } from '@/lib/global'
5
- import * as ThemeMap from '@/themes'
6
- import React from 'react'
5
+ import { useEffect , useState } from 'react'
7
6
import { idToUuid } from 'notion-utils'
8
- import Router from 'next/router'
7
+ import { useRouter } from 'next/router'
9
8
import { isBrowser } from '@/lib/utils'
10
9
import { getNotion } from '@/lib/notion/getNotion'
11
10
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
12
11
import md5 from 'js-md5'
12
+ import dynamic from 'next/dynamic'
13
+ import Loading from '@/components/Loading'
13
14
14
15
/**
15
16
* 根据notion的slug访问页面
@@ -18,14 +19,14 @@ import md5 from 'js-md5'
18
19
*/
19
20
const Slug = props => {
20
21
const { theme, changeLoadingState } = useGlobal ( )
21
- const ThemeComponents = ThemeMap [ theme ]
22
22
const { post, siteInfo } = props
23
- const router = Router . useRouter ( )
23
+ const router = useRouter ( )
24
24
25
25
// 文章锁🔐
26
- const [ lock , setLock ] = React . useState ( post ?. password && post ?. password !== '' )
26
+ const [ lock , setLock ] = useState ( post ?. password && post ?. password !== '' )
27
+ const LayoutSlug = dynamic ( ( ) => import ( `@/themes/${ theme } /LayoutSlug` ) . then ( async ( m ) => { return m . LayoutSlug } ) , { ssr : false , loading : ( ) => < Loading /> } )
27
28
28
- React . useEffect ( ( ) => {
29
+ useEffect ( ( ) => {
29
30
changeLoadingState ( false )
30
31
if ( post ?. password && post ?. password !== '' ) {
31
32
setLock ( true )
@@ -37,6 +38,9 @@ const Slug = props => {
37
38
38
39
setLock ( false )
39
40
}
41
+ router . events . on ( 'routeChangeComplete' , ( ) => {
42
+ window . scrollTo ( { top : 0 , behavior : 'smooth' } )
43
+ } )
40
44
} , [ post ] )
41
45
42
46
if ( ! post ) {
@@ -51,7 +55,8 @@ const Slug = props => {
51
55
}
52
56
} , 8 * 1000 ) // 404时长 8秒
53
57
const meta = { title : `${ props ?. siteInfo ?. title || BLOG . TITLE } | loading` , image : siteInfo ?. pageCover || BLOG . HOME_BANNER_IMAGE }
54
- return < ThemeComponents . LayoutSlug { ...props } showArticleInfo = { true } meta = { meta } />
58
+
59
+ return < LayoutSlug { ...props } showArticleInfo = { true } meta = { meta } />
55
60
}
56
61
57
62
/**
@@ -80,12 +85,8 @@ const Slug = props => {
80
85
tags : post ?. tags
81
86
}
82
87
83
- Router . events . on ( 'routeChangeComplete' , ( ) => {
84
- window . scrollTo ( { top : 0 , behavior : 'smooth' } )
85
- } )
86
-
87
88
return (
88
- < ThemeComponents . LayoutSlug { ...props } showArticleInfo = { true } meta = { meta } />
89
+ < LayoutSlug { ...props } showArticleInfo = { true } meta = { meta } />
89
90
)
90
91
}
91
92
0 commit comments