Merge: Cusdis comments on every page + instant-nav fix
Some checks failed
Deploy Docs / deploy (push) Failing after 24s

This commit is contained in:
Tolaria 2026-06-03 20:28:42 +08:00
commit 2b2edc7505
2 changed files with 24 additions and 3 deletions

View file

@ -80,6 +80,29 @@
function boot() {
initScrollReveal();
initCursorGlow();
initCusdisReload();
}
/**
* Re-initialize Cusdis comment widget after Zensical instant-navigation
* page transitions (XHR-based SPA navigation). Without this, the widget
* only renders on hard-refresh / initial page load.
*/
function initCusdisReload() {
if (typeof document$ === "undefined") return; // not in Zensical context
document$.subscribe(function () {
var el = document.getElementById("cusdis_thread");
if (!el) return;
// Clear stale Cusdis iframe from previous page render
el.innerHTML = "";
// Re-create Cusdis widget for the new page
if (window.CUSDIS && typeof window.CUSDIS.renderTo === "function") {
window.CUSDIS.renderTo(el);
}
});
}
if (document.readyState === "loading") {

View file

@ -1,4 +1,3 @@
{% if page.meta.comments %}
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
<div id="cusdis_thread"
data-host="{{ config.extra.cusdis.host }}"
@ -9,5 +8,4 @@
data-theme="auto">
</div>
<script async defer src="{{ config.extra.cusdis.host }}/js/cusdis.es.js"></script>
<noscript>Please enable JavaScript to view the comments.</noscript>
{% endif %}
<noscript>Please enable JavaScript to view the comments.</noscript>