Files
hello-algo/overrides/partials/comments.html
krahets 60ad99c8ce build
2026-10-30 02:14:20 +08:00

72 lines
2.3 KiB
HTML

{% if page.meta.comments %}
{% from "partials/i18n.html" import ui with context %}
<!-- Check-in button above comments -->
{% include "partials/checkin.html" ignore missing %}
<h5 align="center" id="__comments">{{ ui.comments_prompt }}</h5>
<!-- Insert generated snippet here -->
<script
src="https://giscus.app/client.js"
data-repo="krahets/hello-algo"
data-repo-id="R_kgDOIXtSqw"
data-category="Announcements"
data-category-id="DIC_kwDOIXtSq84CSZk_"
data-mapping="pathname"
data-strict="1"
data-reactions-enabled="1"
data-emit-metadata="1"
data-input-position="top"
data-theme="light"
data-lang="{{ ui.giscus_language }}"
crossorigin="anonymous"
async
>
</script>
<!-- Synchronize Giscus theme with palette -->
<script>
var giscus = document.querySelector("script[src*=giscus]")
function getGiscusTheme() {
var palette = __md_get("__palette")
var isDark = palette && typeof palette.color === "object" && palette.color.scheme === "slate"
return isDark ? "noborder_dark" : "light"
}
/* Set palette on initial load */
giscus.setAttribute("data-theme", getGiscusTheme())
/* The Giscus client creates the iframe asynchronously with an English title. */
;(function() {
function labelCommentsFrame() {
var frame = document.querySelector("iframe.giscus-frame")
if (!frame) return false
frame.setAttribute("title", {{ ui.comments_title | tojson }})
return true
}
if (labelCommentsFrame()) return
var observer = new MutationObserver(function() {
if (labelCommentsFrame()) observer.disconnect()
})
observer.observe(giscus.parentElement, { childList: true, subtree: true })
})()
/* Register event handlers after documented loaded */
document.addEventListener("DOMContentLoaded", function() {
var ref = document.querySelector("[data-md-component=palette]")
if (!ref) return
ref.addEventListener("change", function() {
var theme = getGiscusTheme()
/* Instruct Giscus to change theme */
var frame = document.querySelector(".giscus-frame")
if (!frame) return
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme } } },
"https://giscus.app"
)
})
})
</script>
{% endif %}