mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 12:03:31 +08:00
44 lines
1.2 KiB
HTML
44 lines
1.2 KiB
HTML
{{- with .Site.Params.comments.giscus -}}
|
|
<script
|
|
src="https://giscus.app/client.js"
|
|
data-repo="{{- .repo -}}"
|
|
data-repo-id="{{- .repoID -}}"
|
|
data-category="{{- .category -}}"
|
|
data-category-id="{{- .categoryID -}}"
|
|
data-mapping="{{- default "title" .mapping -}}"
|
|
data-reactions-enabled="1"
|
|
data-emit-metadata="0"
|
|
data-theme="{{- default "light" .lightTheme -}}"
|
|
crossorigin="anonymous"
|
|
async
|
|
></script>
|
|
<script>
|
|
|
|
function setGiscusTheme(theme) {
|
|
let giscus = document.querySelector('iframe.giscus-frame');
|
|
if (giscus) {
|
|
giscus.contentWindow.postMessage(
|
|
{ giscus: { setConfig: { theme: theme } } },
|
|
"https://giscus.app"
|
|
);
|
|
}
|
|
}
|
|
|
|
(function(){
|
|
const head = document.getElementsByTagName("html")[0];
|
|
|
|
addEventListener('message', handler)
|
|
window.addEventListener('onColorSchemeChange', handler)
|
|
|
|
function handler() {
|
|
if (head.getAttribute("data-scheme") == "light") {
|
|
setGiscusTheme('{{- default "light" .lightTheme -}}');
|
|
} else {
|
|
setGiscusTheme('{{- default "dark_dimmed" .darkTheme -}}');
|
|
}
|
|
}
|
|
}());
|
|
|
|
</script>
|
|
{{- end -}}
|