Updated Giscus example to support theme change without reload

This commit is contained in:
squidfunk
2022-01-23 12:33:35 +01:00
parent 6816aa8cd0
commit e6bcb8100f
3 changed files with 23 additions and 3 deletions

View File

@@ -74,7 +74,17 @@ calling the `super()` function at the beginning of the block:
document.addEventListener("DOMContentLoaded", function() {
var ref = document.querySelector("[data-md-component=palette]")
ref.addEventListener("change", function() {
location.reload()
var palette = __md_get("__palette")
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light"
/* Instruct Giscus to change theme */
var frame = document.querySelector(".giscus-frame")
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme } } },
"https://giscus.app"
)
}
})
})
</script>