fix: switch Cusdis to iframe embed to avoid CORS
All checks were successful
Deploy Docs / deploy (push) Successful in 24s

- Replace <script src> approach with programmatic iframe creation
- No cross-origin script loading — avoids CORS blocks entirely
- Guard against missing container with null check
This commit is contained in:
Tolaria 2026-06-03 18:40:04 +08:00
parent 0fbe169815
commit 2537e4d5af

View file

@ -1,13 +1,28 @@
{% if page.meta.comments %} {% if page.meta.comments %}
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2> <h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
<div id="cusdis_thread" <div id="cusdis_thread"></div>
data-host="{{ config.extra.cusdis.host }}" <script>
data-app-id="{{ config.extra.cusdis.app_id }}" (function() {
data-page-id="{{ page.canonical_url }}" var host = "{{ config.extra.cusdis.host }}";
data-page-url="{{ page.canonical_url }}" var appId = "{{ config.extra.cusdis.app_id }}";
data-page-title="{{ page.title }}" var pageId = "{{ page.canonical_url }}";
data-theme="auto"> var pageUrl = "{{ page.canonical_url }}";
</div> var pageTitle = "{{ page.title }}";
<script async defer src="{{ config.extra.cusdis.host }}/js/cusdis.es.js"></script> var theme = "auto";
var iframe = document.createElement("iframe");
iframe.src = host + "/iframe/thread"
+ "?app_id=" + encodeURIComponent(appId)
+ "&page_id=" + encodeURIComponent(pageId)
+ "&page_url=" + encodeURIComponent(pageUrl)
+ "&page_title=" + encodeURIComponent(pageTitle)
+ "&theme=" + theme;
iframe.style.cssText = "width:100%;border:none;min-height:300px";
iframe.title = "Comments";
var container = document.getElementById("cusdis_thread");
if (container) container.appendChild(iframe);
})();
</script>
<noscript>Please enable JavaScript to view the comments.</noscript> <noscript>Please enable JavaScript to view the comments.</noscript>
{% endif %} {% endif %}