feat(giscus): dynamic theme change

This commit is contained in:
mancuoj 2022-12-21 19:47:04 +08:00 committed by GitHub
parent e71d7badd8
commit 2d6b3bb510
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,6 @@
{% extends "base.html" %} {% block disqus %}
{% extends "base.html" %}
{% block disqus %}
<script src="https://giscus.app/client.js"
data-repo="PKUFlyingPig/cs-self-learning"
data-repo-id="R_kgDOGP67ng"
@ -14,4 +16,20 @@
crossorigin="anonymous"
async>
</script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const ref = document.querySelector("[data-md-component=palette]")
ref.addEventListener("change", function () {
var palette = __get("__palette")
if (palette && typeof palette.color === "object") {
const theme = palette.color.scheme === "slate" ? "dark" : "light"
const frame = document.querySelector(".giscus-frame")
frame.contentWindow.postMessage({
giscus: { setConfig: { theme } }
}, "https://giscus.app")
}
})
})
</script>
{% endblock %}