@@ -20,7 +20,26 @@ function boolToStringBool(b: boolean): string {
2020
2121export default ( ( opts : Options ) => {
2222 const Comments : QuartzComponent = ( _props : QuartzComponentProps ) => < div class = "giscus" > </ div >
23+
2324 Comments . afterDOMLoaded = `
25+ const changeTheme = (e) => {
26+ const theme = e.detail.theme
27+ const iframe = document.querySelector('iframe.giscus-frame')
28+ if (!iframe) {
29+ return
30+ }
31+
32+ iframe.contentWindow.postMessage({
33+ giscus: {
34+ setConfig: {
35+ theme: theme
36+ }
37+ }
38+ }, 'https://giscus.app')
39+ }
40+
41+ document.addEventListener("nav", () => {
42+ const giscusContainer = document.querySelector(".giscus")
2443 const giscusScript = document.createElement("script")
2544 giscusScript.src = "https://giscus.app/client.js"
2645 giscusScript.async = true
@@ -38,29 +57,11 @@ export default ((opts: Options) => {
3857
3958 const theme = document.documentElement.getAttribute("saved-theme")
4059 giscusScript.setAttribute("data-theme", theme)
41- document.head.appendChild(giscusScript)
42-
43- const changeTheme = (e) => {
44- const theme = e.detail.theme
45- const iframe = document.querySelector('iframe.giscus-frame')
46- if (!iframe) {
47- return
48- }
49-
50- iframe.contentWindow.postMessage({
51- giscus: {
52- setConfig: {
53- theme: theme
54- }
55- }
56- }, 'https://giscus.app')
57- }
60+ giscusContainer.appendChild(giscusScript)
5861
59- document.addEventListener("nav", () => {
60- document.addEventListener("themechange", changeTheme)
61- window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
62- })
63- `
62+ document.addEventListener("themechange", changeTheme)
63+ window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
64+ })`
6465
6566 return Comments
6667} ) satisfies QuartzComponentConstructor < Options >
0 commit comments