From 5b0ff60ac815d24921f74ece127fb2a7f5edcacf Mon Sep 17 00:00:00 2001 From: Tolaria Date: Wed, 3 Jun 2026 20:28:34 +0800 Subject: [PATCH] feat: add Cusdis comments to every page, fix instant-navigation re-render --- docs/javascripts/extra.js | 23 +++++++++++++++++++++++ overrides/partials/comments.html | 4 +--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/javascripts/extra.js b/docs/javascripts/extra.js index cb44c1b..d3adc8b 100644 --- a/docs/javascripts/extra.js +++ b/docs/javascripts/extra.js @@ -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") { diff --git a/overrides/partials/comments.html b/overrides/partials/comments.html index a763acb..9248487 100644 --- a/overrides/partials/comments.html +++ b/overrides/partials/comments.html @@ -1,4 +1,3 @@ -{% if page.meta.comments %}

{{ lang.t("meta.comments") }}

- -{% endif %} \ No newline at end of file + \ No newline at end of file