diff --git a/docs/setup/adding-a-comment-system.md b/docs/setup/adding-a-comment-system.md index a86ade118..3bfa77838 100644 --- a/docs/setup/adding-a-comment-system.md +++ b/docs/setup/adding-a-comment-system.md @@ -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" + ) + } }) }) diff --git a/material/overrides/blog.html b/material/overrides/blog.html index 4b177e7e0..ae59b4cb7 100644 --- a/material/overrides/blog.html +++ b/material/overrides/blog.html @@ -6,5 +6,5 @@ {{ super() }}

{{ lang.t("meta.comments") }}

- + {% endblock %} diff --git a/src/overrides/blog.html b/src/overrides/blog.html index 32987668f..240090520 100644 --- a/src/overrides/blog.html +++ b/src/overrides/blog.html @@ -57,7 +57,17 @@ 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" + ) + } }) })