Added dark mode support for Giscus

This commit is contained in:
squidfunk 2022-01-16 11:16:07 +01:00
parent 09c0e1cb6e
commit 9511569d05
2 changed files with 20 additions and 0 deletions

View File

@ -6,4 +6,5 @@
{{ super() }} {{ super() }}
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2> <h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
<script src="https://giscus.app/client.js" data-repo="squidfunk/mkdocs-material" data-repo-id="MDEwOlJlcG9zaXRvcnk1MDYxNzQyOA==" data-category="_" data-category-id="DIC_kwDOAwRcVM4CAtJY" data-mapping="pathname" data-reactions-enabled="1" data-emit-metadata="1" data-theme="light" data-lang="en" crossorigin="anonymous" async></script> <script src="https://giscus.app/client.js" data-repo="squidfunk/mkdocs-material" data-repo-id="MDEwOlJlcG9zaXRvcnk1MDYxNzQyOA==" data-category="_" data-category-id="DIC_kwDOAwRcVM4CAtJY" data-mapping="pathname" data-reactions-enabled="1" data-emit-metadata="1" data-theme="light" data-lang="en" crossorigin="anonymous" async></script>
<script>var giscus,palette=__md_get("__palette");palette&&"object"==typeof palette.color&&"slate"===palette.color.scheme&&(giscus=document.querySelector("script[src*=giscus]")).setAttribute("data-theme","dark"),document.addEventListener("DOMContentLoaded",function(){var t=document.querySelector("[data-md-component=palette]");component$.subscribe(function(e){e.ref===t&&location.reload()})})</script>
{% endblock %} {% endblock %}

View File

@ -43,4 +43,23 @@
async async
> >
</script> </script>
<!-- Reload on palette change -->
<script>
var palette = __md_get("__palette")
if (palette && typeof palette.color === "object")
if (palette.color.scheme === "slate") {
var giscus = document.querySelector("script[src*=giscus]")
giscus.setAttribute("data-theme", "dark")
}
/* Reload on palette change */
document.addEventListener("DOMContentLoaded", function() {
var ref = document.querySelector("[data-md-component=palette]")
component$.subscribe(function (component) {
if (component.ref === ref)
location.reload()
})
})
</script>
{% endblock %} {% endblock %}