forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment.js
99 lines (84 loc) · 2.41 KB
/
Comment.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import BLOG from '@/blog.config'
import dynamic from 'next/dynamic'
import Tabs from '@/components/Tabs'
import { useGlobal } from '@/lib/global'
import React from 'react'
import { useRouter } from 'next/router'
const WalineComponent = dynamic(
() => {
return import('@/components/WalineComponent')
},
{ ssr: false }
)
const CusdisComponent = dynamic(
() => {
return import('@/components/CusdisComponent')
},
{ ssr: false }
)
const GitalkComponent = dynamic(
() => {
return import('@/components/Gitalk')
},
{ ssr: false }
)
const UtterancesComponent = dynamic(
() => {
return import('@/components/Utterances')
},
{ ssr: false }
)
const GiscusComponent = dynamic(
() => {
return import('@/components/Giscus')
},
{ ssr: false }
)
const ValineComponent = dynamic(() => import('@/components/ValineComponent'), {
ssr: false
})
const Comment = ({ frontMatter }) => {
const { isDarkMode } = useGlobal()
const router = useRouter()
React.useEffect(() => {
// 跳转到评论区
setTimeout(() => {
if (window.location.href.indexOf('target=comment') > -1) {
const url = router.asPath.replace('?target=comment', '')
history.replaceState({}, '', url)
const commentNode = document.getElementById('comment')
commentNode.scrollIntoView({ block: 'start', behavior: 'smooth' })
}
}, 200)
}, [])
if (!frontMatter) {
return <>Loading...</>
}
return (
<div id='comment' className='comment mt-5 text-gray-800 dark:text-gray-300'>
<Tabs>
{ BLOG.COMMENT_WALINE_SERVER_URL && (<div key='Waline'>
<WalineComponent/>
</div>) }
{BLOG.COMMENT_VALINE_APP_ID && (<div key='Valine' name='reply'>
<ValineComponent path={frontMatter.id}/>
</div>)}
{BLOG.COMMENT_GISCUS_REPO && (
<div key="Giscus">
<GiscusComponent isDarkMode={isDarkMode} className="px-2" />
</div>
)}
{BLOG.COMMENT_CUSDIS_APP_ID && (<div key='Cusdis'>
<CusdisComponent frontMatter={frontMatter}/>
</div>)}
{BLOG.COMMENT_UTTERRANCES_REPO && (<div key='Utterance'>
<UtterancesComponent issueTerm={frontMatter.id} className='px-2' />
</div>)}
{BLOG.COMMENT_GITALK_CLIENT_ID && (<div key='GitTalk'>
<GitalkComponent frontMatter={frontMatter}/>
</div>)}
</Tabs>
</div>
)
}
export default Comment