|
125 | 125 |
|
126 | 126 | // Re-render KaTeX |
127 | 127 | renderKaTeX(); |
| 128 | + |
| 129 | + // Re-load Giscus |
| 130 | + loadGiscus(); |
128 | 131 | }) |
129 | 132 |
|
| 133 | + // --- Giscus Logic --- |
| 134 | + function loadGiscus() { |
| 135 | + const container = document.querySelector('.giscus-container'); |
| 136 | + if (!container) return; |
| 137 | + |
| 138 | + const script = document.createElement('script'); |
| 139 | + script.src = "https://giscus.app/client.js"; |
| 140 | + |
| 141 | + // Determine current theme |
| 142 | + const isDark = document.documentElement.dataset.scheme === 'dark'; |
| 143 | + const theme = isDark ? container.dataset.themeDark : container.dataset.themeLight; |
| 144 | + |
| 145 | + for (const attr of container.attributes) { |
| 146 | + if (attr.name.startsWith('data-')) { |
| 147 | + script.setAttribute(attr.name, attr.value); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + // Set dynamic theme |
| 152 | + script.setAttribute('data-theme', theme); |
| 153 | + |
| 154 | + script.crossOrigin = "anonymous"; |
| 155 | + script.async = true; |
| 156 | + |
| 157 | + container.innerHTML = ''; |
| 158 | + container.appendChild(script); |
| 159 | + } |
| 160 | + |
| 161 | + // Listen for theme changes |
| 162 | + window.addEventListener('onColorSchemeChange', (e) => { |
| 163 | + const container = document.querySelector('.giscus-container'); |
| 164 | + if (!container) return; |
| 165 | + |
| 166 | + const newTheme = e.detail === 'dark' ? container.dataset.themeDark : container.dataset.themeLight; |
| 167 | + |
| 168 | + const iframe = document.querySelector('iframe.giscus-frame'); |
| 169 | + if (iframe) { |
| 170 | + iframe.contentWindow.postMessage({ |
| 171 | + giscus: { |
| 172 | + setConfig: { |
| 173 | + theme: newTheme |
| 174 | + } |
| 175 | + } |
| 176 | + }, 'https://giscus.app'); |
| 177 | + } |
| 178 | + }); |
| 179 | + |
| 180 | + // Initial load |
| 181 | + loadGiscus(); |
| 182 | + |
130 | 183 | // --- KaTeX Logic --- |
131 | 184 | async function renderKaTeX() { |
132 | 185 | let katex = document.querySelector(".math-katex"); |
|
0 commit comments