mirror of
https://github.com/PKUFlyingPig/cs-self-learning.git
synced 2026-06-24 02:16:58 +08:00
feat(giscus): dynamic theme change
This commit is contained in:
parent
e71d7badd8
commit
2d6b3bb510
1 changed files with 29 additions and 11 deletions
|
|
@ -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 %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue