mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2024-11-23 10:21:46 +01:00
feat(comments): add lang option for giscus (#498)
This commit is contained in:
parent
98923b1dd7
commit
24cd07589b
2 changed files with 18 additions and 17 deletions
|
@ -95,6 +95,7 @@ params:
|
|||
darkTheme:
|
||||
reactionsEnabled: 1
|
||||
emitMetadata: 0
|
||||
lang:
|
||||
|
||||
gitalk:
|
||||
owner:
|
||||
|
|
|
@ -9,41 +9,41 @@
|
|||
data-reactions-enabled="{{- default 1 .reactionsEnabled -}}"
|
||||
data-emit-metadata="{{- default 0 .emitMetadata -}}"
|
||||
data-theme="{{- default `light` .lightTheme -}}"
|
||||
data-lang="{{- default `en` .lang -}}"
|
||||
crossorigin="anonymous"
|
||||
async
|
||||
></script>
|
||||
<script>
|
||||
function setGiscusTheme(theme) {
|
||||
let giscus = document.querySelector('iframe.giscus-frame');
|
||||
let giscus = document.querySelector("iframe.giscus-frame");
|
||||
if (giscus) {
|
||||
giscus.contentWindow.postMessage(
|
||||
{
|
||||
giscus: {
|
||||
setConfig: {
|
||||
theme: theme
|
||||
}
|
||||
}
|
||||
theme: theme,
|
||||
},
|
||||
},
|
||||
},
|
||||
"https://giscus.app"
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
(function(){
|
||||
addEventListener('message', (e) => {
|
||||
if (event.origin !== 'https://giscus.app') return;
|
||||
handler()
|
||||
(function () {
|
||||
addEventListener("message", (e) => {
|
||||
if (event.origin !== "https://giscus.app") return;
|
||||
handler();
|
||||
});
|
||||
window.addEventListener('onColorSchemeChange', handler);
|
||||
window.addEventListener("onColorSchemeChange", handler);
|
||||
|
||||
function handler() {
|
||||
if (document.documentElement.dataset.scheme === "light") {
|
||||
setGiscusTheme('{{- default "light" .lightTheme -}}');
|
||||
} else {
|
||||
setGiscusTheme('{{- default "dark_dimmed" .darkTheme -}}');
|
||||
};
|
||||
};
|
||||
}());
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{{- end -}}
|
||||
|
||||
|
|
Loading…
Reference in a new issue