forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Giscus.js
48 lines (44 loc) · 1.57 KB
/
Giscus.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
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { loadExternalResource } from '@/lib/utils'
import { useEffect } from 'react'
// import Giscus from '@giscus/react'
/**
* Giscus评论 @see https://giscus.app/zh-CN
* Contribute by @txs https://github.com/txs/NotionNext/commit/1bf7179d0af21fb433e4c7773504f244998678cb
* @returns {JSX.Element}
* @constructor
*/
const GiscusComponent = () => {
const { isDarkMode } = useGlobal()
const theme = isDarkMode ? 'dark' : 'light'
useEffect(() => {
loadExternalResource('/js/giscus.js', 'js').then(() => {
if (window?.Giscus?.init) {
window?.Giscus?.init('#giscus')
}
})
return () => {
window?.Giscus?.destroy()
}
}, [isDarkMode])
return (
<div
id='giscus'
data-repo={siteConfig('COMMENT_GISCUS_REPO')}
data-repo-id={siteConfig('COMMENT_GISCUS_REPO_ID')}
// data-category='{{ $.Site.Params.giscus.dataCategory }}'
data-category-id={siteConfig('COMMENT_GISCUS_CATEGORY_ID')}
data-mapping={siteConfig('COMMENT_GISCUS_MAPPING')}
// data-strict='0'
data-reactions-enabled={siteConfig('COMMENT_GISCUS_REACTIONS_ENABLED')}
data-emit-metadata={siteConfig('COMMENT_GISCUS_EMIT_METADATA')}
data-input-position={siteConfig('COMMENT_GISCUS_INPUT_POSITION')}
data-theme={theme}
data-lang={siteConfig('COMMENT_GISCUS_LANG')}
data-loading={siteConfig('COMMENT_GISCUS_LOADING')}
// crossorigin={siteConfig('COMMENT_GISCUS_CROSSORIGIN')}
></div>
)
}
export default GiscusComponent