Skip to content

Commit bbef909

Browse files
authored
Update giscus.ejs to fix giscus color on load
1 parent 252bc95 commit bbef909

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
<script src="https://giscus.app/client.js"
2-
data-repo="<%- giscus.repo %>"
3-
data-repo-id="<%- giscus['repo-id'] %>"
4-
data-category="<%- giscus.category %>"
5-
data-category-id="<%- giscus['category-id'] %>"
6-
data-mapping="<%- giscus.mapping %>"
7-
data-reactions-enabled="<%- giscus['reactions-enabled'] ? 1 : 0 %>"
8-
data-emit-metadata="0"
9-
data-input-position="<%- giscus['input-position'] %>"
10-
data-theme="<%- giscus.theme %>"
11-
data-lang="<%- giscus.language %>"
12-
crossorigin="anonymous"
13-
<%- giscus.loading ? `data-loading=${giscus.loading}` : '' %>
14-
async>
15-
</script>
161
<input type="hidden" id="giscus-base-theme" value="<%- giscus.baseTheme %>">
17-
<input type="hidden" id="giscus-alt-theme" value="<%- giscus.altTheme %>">
2+
<input type="hidden" id="giscus-alt-theme" value="<%- giscus.altTheme %>">
3+
<script>
4+
setTimeout(() => {
5+
var bodyClass = window.document.body.classList;
6+
const GetTheme = () => {
7+
const baseTheme = document.getElementById('giscus-base-theme').value;
8+
const altTheme = document.getElementById('giscus-alt-theme').value;
9+
return bodyClass.contains('quarto-dark') ? altTheme : baseTheme;
10+
};
11+
const script = document.createElement("script");
12+
script.src = "https://giscus.app/client.js";
13+
script.async = true;
14+
script.dataset.repo = "<%- giscus.repo %>";
15+
script.dataset.repoId = "<%- giscus['repo-id'] %>";
16+
script.dataset.category = "<%- giscus.category %>";
17+
script.dataset.categoryId = "<%- giscus['category-id'] %>";
18+
script.dataset.mapping = "<%- giscus.mapping %>";
19+
script.dataset.reactionsEnabled = "<%- giscus['reactions-enabled'] ? 1 : 0 %>";
20+
script.dataset.emitMetadata = "0";
21+
script.dataset.inputPosition = "<%- giscus['input-position'] %>";
22+
script.dataset.theme = GetTheme();
23+
script.dataset.lang = "<%- giscus.language %>";
24+
script.crossOrigin = "anonymous";
25+
// Insert the Giscus script after the current script
26+
document.getElementById("quarto-content").appendChild(script);
27+
}, 50);
28+
</script>

0 commit comments

Comments
 (0)