Skip to content

Commit c4cd4bf

Browse files
feat(comments): giscus integration (#304)
Co-authored-by: Jimmy Cai <github@jimmycai.com>
1 parent bcbba1e commit c4cd4bf

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

exampleSite/config.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ params:
9393
path:
9494
lang:
9595

96+
giscus:
97+
repo:
98+
repoID:
99+
category:
100+
categoryID:
101+
mapping:
102+
lightTheme:
103+
darkTheme:
104+
reactionsEnabled: 1
105+
emitMetadata: 0
106+
96107
widgets:
97108
enabled:
98109
- search
@@ -143,8 +154,8 @@ menu:
143154
weight: -100
144155
pre: home
145156
params:
146-
### For demonstration purpose, the home link will be open in a new tab
147-
newTab: true
157+
### For demonstration purpose, the home link will be open in a new tab
158+
newTab: true
148159

149160
related:
150161
includeNewer: true
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{- with .Site.Params.comments.giscus -}}
2+
<script
3+
src="https://giscus.app/client.js"
4+
data-repo="{{- .repo -}}"
5+
data-repo-id="{{- .repoID -}}"
6+
data-category="{{- .category -}}"
7+
data-category-id="{{- .categoryID -}}"
8+
data-mapping="{{- default `title` .mapping -}}"
9+
data-reactions-enabled="{{- default 1 .reactionsEnabled -}}"
10+
data-emit-metadata="{{- default 0 .emitMetadata -}}"
11+
data-theme="{{- default `light` .lightTheme -}}"
12+
crossorigin="anonymous"
13+
async
14+
></script>
15+
<script>
16+
function setGiscusTheme(theme) {
17+
let giscus = document.querySelector('iframe.giscus-frame');
18+
if (giscus) {
19+
giscus.contentWindow.postMessage(
20+
{
21+
giscus: {
22+
setConfig: {
23+
theme: theme
24+
}
25+
}
26+
},
27+
"https://giscus.app"
28+
);
29+
};
30+
};
31+
32+
(function(){
33+
addEventListener('message', (e) => {
34+
if (event.origin !== 'https://giscus.app') return;
35+
handler()
36+
});
37+
window.addEventListener('onColorSchemeChange', handler);
38+
39+
function handler() {
40+
if (document.documentElement.dataset.scheme === "light") {
41+
setGiscusTheme('{{- default "light" .lightTheme -}}');
42+
} else {
43+
setGiscusTheme('{{- default "dark_dimmed" .darkTheme -}}');
44+
};
45+
};
46+
}());
47+
</script>
48+
{{- end -}}
49+

0 commit comments

Comments
 (0)