-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
/
Copy path_app.js
75 lines (67 loc) · 2.04 KB
/
_app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// import '@/styles/animate.css' // @see https://animate.style/
import '@/styles/globals.css'
import '@/styles/utility-patterns.css'
// core styles shared by all of react-notion-x (required)
import '@/styles/notion.css' // 重写部分notion样式
import 'react-notion-x/src/styles.css' // 原版的react-notion-x
import useAdjustStyle from '@/hooks/useAdjustStyle'
import { GlobalContextProvider } from '@/lib/global'
import { getBaseLayoutByTheme } from '@/themes/theme'
import { useRouter } from 'next/router'
import { useCallback, useMemo } from 'react'
import { getQueryParam } from '../lib/utils'
// 各种扩展插件 这个要阻塞引入
import BLOG from '@/blog.config'
import ExternalPlugins from '@/components/ExternalPlugins'
import SEO from '@/components/SEO'
import { zhCN } from '@clerk/localizations'
import dynamic from 'next/dynamic'
// import { ClerkProvider } from '@clerk/nextjs'
const ClerkProvider = dynamic(() =>
import('@clerk/nextjs').then(m => m.ClerkProvider)
)
/**
* App挂载DOM 入口文件
* @param {*} param0
* @returns
*/
const MyApp = ({ Component, pageProps }) => {
// 一些可能出现 bug 的样式,可以统一放入该钩子进行调整
useAdjustStyle()
const route = useRouter()
const theme = useMemo(() => {
return (
getQueryParam(route.asPath, 'theme') ||
pageProps?.NOTION_CONFIG?.THEME ||
BLOG.THEME
)
}, [route])
// 整体布局
const GLayout = useCallback(
props => {
const Layout = getBaseLayoutByTheme(theme)
return <Layout {...props} />
},
[theme]
)
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
const content = (
<GlobalContextProvider {...pageProps}>
<GLayout {...pageProps}>
<SEO {...pageProps} />
<Component {...pageProps} />
</GLayout>
<ExternalPlugins {...pageProps} />
</GlobalContextProvider>
)
return (
<>
{enableClerk ? (
<ClerkProvider localization={zhCN}>{content}</ClerkProvider>
) : (
content
)}
</>
)
}
export default MyApp