-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comments): add Giscus support (#50)
* feat(comments) add Giscus support * feat: default value for reactionsEnabled and emitMetadata * feat: support custom mapping * fix: add quote * style: giscus border and top padding
- Loading branch information
WingLim
authored
Oct 8, 2021
1 parent
2c54bd4
commit 7bf7c39
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,8 @@ | |
|
||
#cusdis_thread { | ||
padding-top: 2rem; | ||
} | ||
|
||
.giscus { | ||
padding-top: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script src="https://giscus.app/client.js" | ||
data-repo="{{ .Site.Params.comments.giscus.repo }}" | ||
data-repo-id="{{ .Site.Params.comments.giscus.id }}" | ||
{{ with .Site.Params.comments.giscus.category }} | ||
data-category="{{ .name }}" | ||
data-category-id="{{ .id }}" | ||
{{ end }} | ||
data-mapping="{{ .Site.Params.comments.giscus.mapping | default "pathname" }}" | ||
data-reactions-enabled="{{ .Site.Params.comments.giscus.reactionsEnabled | default 1 }}" | ||
data-emit-metadata="{{ .Site.Params.comments.giscus.emitMetadata | default 0 }}" | ||
data-theme="light" | ||
crossorigin="anonymous" | ||
async | ||
> | ||
</script> | ||
|
||
<script> | ||
function setGiscusTeheme(theme) { | ||
let giscus = document.querySelector('.giscus iframe'); | ||
if (giscus) { | ||
giscus.contentWindow.postMessage( | ||
{ | ||
giscus: { | ||
setConfig: { | ||
theme: theme | ||
} | ||
} | ||
}, | ||
'https://giscus.app' | ||
) | ||
} | ||
} | ||
|
||
addEventListener('message', event => { | ||
if (event.origin !== 'https://giscus.app') return; | ||
setGiscusTeheme(document.documentElement.dataset.userColorScheme) | ||
}); | ||
|
||
window.addEventListener('onColorSchemeChange', (e) => { | ||
setGiscusTeheme(e.detail) | ||
}) | ||
</script> |