1
1
< section >
2
2
< h2 > Comments</ h2 >
3
- < div id ="comments-utteranc "> </ div >
3
+ < div id ="comments-giscus "> </ div >
4
4
</ section >
5
5
6
6
< script type ="text/javascript ">
@@ -9,35 +9,41 @@ <h2>Comments</h2>
9
9
return document . documentElement . getAttribute ( 'data-theme' ) || document . body . classList . contains ( 'dark' ) ? 'dark' : 'light' ;
10
10
}
11
11
12
- function loadUtterances ( darkMode = false ) {
13
- const commentContainer = document . getElementById ( "comments-utteranc" ) ;
12
+ function loadComment ( darkMode = false ) {
13
+ const currentUrl = URL . parse ( window . location . href ) ;
14
+ const paths = currentUrl . pathname . split ( '/' ) . filter ( x => x != '' ) ;
15
+ const isChinese = paths . length > 0 && paths [ 0 ] == "zh" ;
16
+ const commentContainer = document . getElementById ( "comments-giscus" ) ;
14
17
if ( commentContainer !== null ) {
15
18
commentContainer . innerHTML = ''
16
19
const commentScript = document . createElement ( "script" ) ;
17
- commentScript . setAttribute ( "id" , "utteranc" ) ;
18
- commentScript . setAttribute ( "src" , "https://utteranc.es/client.js" ) ;
20
+ commentScript . setAttribute ( "src" , "https://giscus.app/client.js" ) ;
19
21
commentScript . setAttribute ( "data-repo" , "ramsayleung/comment" ) ;
20
- commentScript . setAttribute ( "data-category" , "Announcements" ) ;
22
+ commentScript . setAttribute ( "data-repo-id" , "MDEwOlJlcG9zaXRvcnkzMDk2NjQ1NDk=" ) ;
23
+ commentScript . setAttribute ( "data-category" , "General" ) ;
24
+ commentScript . setAttribute ( "data-category-id" , "DIC_kwDOEnUbJc4Cltnz" ) ;
21
25
commentScript . setAttribute ( "data-mapping" , "pathname" ) ;
26
+ commentScript . setAttribute ( "data-strict" , "0" ) ;
22
27
commentScript . setAttribute ( "data-reactions-enabled" , "1" ) ;
23
28
commentScript . setAttribute ( "data-emit-metadata" , "0" ) ;
24
- commentScript . setAttribute ( "data-theme " , darkMode ? "github-dark" : "github-light ") ;
25
- commentScript . setAttribute ( "data-issue-term " , "title ") ;
29
+ commentScript . setAttribute ( "data-input-position " , "bottom ") ;
30
+ commentScript . setAttribute ( "data-theme " , darkMode ? "dark" : "light ") ;
26
31
commentScript . setAttribute ( "crossorigin" , "anonymous" ) ;
32
+ commentScript . setAttribute ( "data-lang" , isChinese ? "zh-CN" : "en" ) ;
27
33
commentScript . setAttribute ( "async" , "true" ) ;
28
34
commentContainer . appendChild ( commentScript ) ;
29
35
}
30
36
}
31
37
32
38
const isDarkMode = getCurrentTheme ( ) === 'dark' ;
33
- loadUtterances ( isDarkMode ) ;
39
+ loadComment ( isDarkMode ) ;
34
40
35
41
// Watch for theme changes
36
42
const themeObserver = new MutationObserver ( ( mutations ) => {
37
43
mutations . forEach ( ( mutation ) => {
38
44
if ( mutation . type === 'attributes' && mutation . attributeName === 'class' ) {
39
45
const isDarkMode = getCurrentTheme ( ) === 'dark' ;
40
- loadUtterances ( isDarkMode ) ;
46
+ loadComment ( isDarkMode ) ;
41
47
console . log ( `changing theme` ) ;
42
48
}
43
49
} ) ;
0 commit comments