@@ -20,7 +20,26 @@ function boolToStringBool(b: boolean): string {
20
20
21
21
export default ( ( opts : Options ) => {
22
22
const Comments : QuartzComponent = ( _props : QuartzComponentProps ) => < div class = "giscus" > </ div >
23
+
23
24
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")
24
43
const giscusScript = document.createElement("script")
25
44
giscusScript.src = "https://giscus.app/client.js"
26
45
giscusScript.async = true
@@ -38,29 +57,11 @@ export default ((opts: Options) => {
38
57
39
58
const theme = document.documentElement.getAttribute("saved-theme")
40
59
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)
58
61
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
+ })`
64
65
65
66
return Comments
66
67
} ) satisfies QuartzComponentConstructor < Options >
0 commit comments