Skip to content

Commit e995335

Browse files
toggle giscus as soon as it loads
i did see the iframe query fail once, but was unable to repro otherwise this seems to be reliable
1 parent 69f60ae commit e995335

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/resources/formats/html/giscus/giscus.ejs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,15 @@
1313
<%- giscus.loading ? `data-loading=${giscus.loading}` : '' %>
1414
async>
1515
</script>
16+
<script type="application/javascript">
17+
window.document.addEventListener("DOMContentLoaded", function (event) {
18+
var giscusIframe = window.document.querySelector('iframe.giscus-frame');
19+
giscusIframe.addEventListener("load", function() {
20+
window.setTimeout(() => {
21+
window.toggleGiscusIfUsed(window.hasAlternateSentinel(), authorPrefersDark);
22+
}, 100);
23+
});
24+
});
25+
</script>
1626
<input type="hidden" id="giscus-base-theme" value="<%- giscus.baseTheme %>">
1727
<input type="hidden" id="giscus-alt-theme" value="<%- giscus.altTheme %>">

src/resources/formats/html/templates/quarto-html-before-body.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189
toggleGiscusIfUsed(toAlternate, darkModeDefault);
190190
};
191191
192+
window.toggleGiscusIfUsed = toggleGiscusIfUsed;
193+
192194
<% if (respectUserColorScheme) { %>
193195
queryPrefersDark.addEventListener("change", e => {
194196
if(window.localStorage.getItem("quarto-color-scheme") !== null)

0 commit comments

Comments
 (0)