@@ -2,6 +2,7 @@ import * as React from 'react'
2
2
import { Routes , Link , Route , Navigate , useLocation } from 'react-router-dom'
3
3
import cx from 'classnames'
4
4
import { ifDev , ifProd , ifPrerender } from 'crd-client-utils'
5
+ const Giscus = require ( '@giscus/react' )
5
6
import Menu from '../component/Menu'
6
7
import Icon from '../component/Icon'
7
8
import Affix from '../component/Affix'
@@ -15,7 +16,7 @@ import logo from '../crd.logo.svg'
15
16
import styles from './index.less'
16
17
import '../style/mobile.less'
17
18
18
- const { useState, useEffect } = React
19
+ const { useState, useEffect, useMemo } = React
19
20
const SubMenu = Menu . SubMenu
20
21
21
22
function BasicLayout ( {
@@ -30,8 +31,10 @@ function BasicLayout({
30
31
branch = 'main' ,
31
32
language = 'en' ,
32
33
menuOpenKeys,
33
- tags
34
+ tags,
35
+ comment
34
36
} = DOCSCONFIG || { }
37
+
35
38
const [ inlineCollapsed , setInlineCollapsed ] = useState ( true )
36
39
const [ selectedKey , setSelectedKey ] = useState ( '' )
37
40
const curOpenKeys = getOpenSubMenuKeys ( {
@@ -150,7 +153,7 @@ function BasicLayout({
150
153
)
151
154
}
152
155
/**
153
- * this section is to show article's relevant information
156
+ * This section is to show article's relevant information
154
157
* such as edit in github and so on.
155
158
*/
156
159
const renderPageHeader = ( ) => {
@@ -176,8 +179,34 @@ function BasicLayout({
176
179
</ div >
177
180
)
178
181
}
182
+
183
+ /**
184
+ * This section is to render comment area.
185
+ * Every pathname should has its own comment module.
186
+ */
187
+ const renderComment = useMemo ( ( ) => {
188
+ return < Giscus
189
+ key = { pathname }
190
+ id = "comments"
191
+ repo = { `${ user } /${ repo } ` }
192
+ category = "General"
193
+ categoryId = "DIC_kwDOD_mJNs4CSd1W"
194
+ mapping = "pathname"
195
+ strict = "0"
196
+ reactionsEnabled = "1"
197
+ emitMetadata = "0"
198
+ inputPosition = "top"
199
+ theme = "preferred_color_scheme"
200
+ lang = "en"
201
+ loading = "lazy"
202
+ crossorigin = "anonymous"
203
+ async
204
+ { ...comment ?. GiscusConfig }
205
+ />
206
+ } , [ pathname ] )
207
+
179
208
/**
180
- * this section is to show article's relevant information
209
+ * This section is to show article's relevant information
181
210
* such as edit in created time、edited time and so on.
182
211
*/
183
212
const renderPageFooter = ( ) => {
@@ -283,6 +312,7 @@ function BasicLayout({
283
312
{ /* Todo: follow up how to use Redirect to back up the rest of route. */ }
284
313
{ /* <Redirect path='/' to={ifAddPrefix ? `/${repo}/404` : `/404`} /> */ }
285
314
</ Routes >
315
+ { comment ?. GiscusConfig ? renderComment : null }
286
316
{ renderPageFooter ( ) }
287
317
</ div >
288
318
)
0 commit comments