|
1 | 1 | <input type="hidden" id="giscus-base-theme" value="<%- giscus.baseTheme %>"> |
2 | 2 | <input type="hidden" id="giscus-alt-theme" value="<%- giscus.altTheme %>"> |
3 | 3 | <script> |
| 4 | +async function loadGiscusWhenReady() { |
| 5 | + while (!document.body.classList.contains('quarto-light') && !document.body.classList.contains('quarto-dark')) { |
| 6 | + await new Promise(resolve => setTimeout(resolve, 50)); |
| 7 | + } |
| 8 | +
|
| 9 | + // Function to get the theme based on body class |
| 10 | + const getTheme = () => { |
| 11 | + const baseTheme = document.getElementById('giscus-base-theme').value; |
| 12 | + const altTheme = document.getElementById('giscus-alt-theme').value; |
| 13 | + return document.body.classList.contains('quarto-dark') ? altTheme : baseTheme; |
| 14 | + }; |
| 15 | +
|
| 16 | + // Create the Giscus script and add it to the desired location |
| 17 | + const script = document.createElement("script"); |
| 18 | + script.src = "https://giscus.app/client.js"; |
| 19 | + script.async = true; |
| 20 | + script.dataset.repo = "<%- giscus.repo %>"; |
| 21 | + script.dataset.repoId = "<%- giscus['repo-id'] %>"; |
| 22 | + script.dataset.category = "<%- giscus.category %>"; |
| 23 | + script.dataset.categoryId = "<%- giscus['category-id'] %>"; |
| 24 | + script.dataset.mapping = "<%- giscus.mapping %>"; |
| 25 | + script.dataset.reactionsEnabled = "<%- giscus['reactions-enabled'] ? 1 : 0 %>"; |
| 26 | + script.dataset.emitMetadata = "0"; |
| 27 | + script.dataset.inputPosition = "<%- giscus['input-position'] %>"; |
| 28 | + script.dataset.theme = getTheme(); |
| 29 | + script.dataset.lang = "<%- giscus.language %>"; |
| 30 | + script.crossOrigin = "anonymous"; |
| 31 | +
|
| 32 | + // Append the script to the desired div instead of at the end of the body |
| 33 | + document.getElementById("quarto-content").appendChild(script); |
| 34 | +} |
| 35 | +
|
| 36 | +// Call the async function to start the loop |
| 37 | +loadGiscusWhenReady(); |
4 | 38 | setTimeout(() => { |
5 | 39 | var bodyClass = window.document.body.classList; |
6 | 40 | const GetTheme = () => { |
|
0 commit comments