feat(comments): add lang option for giscus (#498)

This commit is contained in:
zhixuan 2022-03-03 05:31:44 +09:00 committed by GitHub
parent 98923b1dd7
commit 24cd07589b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 17 deletions

View file

@ -95,6 +95,7 @@ params:
darkTheme:
reactionsEnabled: 1
emitMetadata: 0
lang:
gitalk:
owner:

View file

@ -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()
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 -}}