From f0e60cf1b86422285ca0ae2f1b663e34b6f7524b Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 6 Feb 2025 11:18:12 +0800 Subject: fix: reload giscus after swup Former-commit-id: 56fc3d86eb5890841a85bc6c50b1de7d95ced3fa --- layouts/partials/scripts.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index b77a3f73..9c980c77 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -25,6 +25,34 @@ loadToc(); /* === littlefoot === */ littlefoot.littlefoot(littlefootOptions) +/* === giscus === */ +function loadGiscus() { + const giscusContainer = document.querySelector('.giscus'); // Make sure this matches your Giscus container class + if (giscusContainer) { + // Remove old Giscus iframe + giscusContainer.innerHTML = ''; + + // Create and append a new script + const script = document.createElement('script'); + script.src = 'https://giscus.app/client.js'; + script.setAttribute('data-repo', 'your/repo'); + script.setAttribute('data-repo-id', 'your-repo-id'); + script.setAttribute('data-category', 'General'); + script.setAttribute('data-category-id', 'your-category-id'); + script.setAttribute('data-mapping', 'pathname'); + script.setAttribute('data-strict', '0'); + script.setAttribute('data-reactions-enabled', '1'); + script.setAttribute('data-emit-metadata', '0'); + script.setAttribute('data-input-position', 'bottom'); + script.setAttribute('data-theme', 'light'); + script.setAttribute('data-lang', 'en'); + script.crossOrigin = 'anonymous'; + script.async = true; + + giscusContainer.appendChild(script); + } +} + /* === swup === */ const swup = new Swup({ linkSelector: 'a[href]:not(.no-swup)' @@ -36,5 +64,6 @@ swup.hooks.on('page:view', () => { littlefoot.littlefoot(littlefootOptions); initCalHeatmap(); initPagefind(); + loadGiscus(); }); -- cgit v1.2.3