fix comments on spa
This commit is contained in:
parent
34fde07cf8
commit
52e31600a6
@ -19,8 +19,12 @@ function boolToStringBool(b: boolean): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default ((opts: Options) => {
|
export default ((opts: Options) => {
|
||||||
const Comments: QuartzComponent = (_props: QuartzComponentProps) => <div class="giscus"></div>
|
const Comments: QuartzComponent = (props: QuartzComponentProps) => {
|
||||||
Comments.afterDOMLoaded = `
|
props.externalResources.js.push({
|
||||||
|
loadTime: "afterDOMReady",
|
||||||
|
spaPreserve: true,
|
||||||
|
contentType: "inline",
|
||||||
|
script: `
|
||||||
const giscusScript = document.createElement("script")
|
const giscusScript = document.createElement("script")
|
||||||
giscusScript.src = "https://giscus.app/client.js"
|
giscusScript.src = "https://giscus.app/client.js"
|
||||||
giscusScript.async = true
|
giscusScript.async = true
|
||||||
@ -57,10 +61,21 @@ export default ((opts: Options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
|
iframe.contentWindow.postMessage({
|
||||||
|
giscus: {
|
||||||
|
setConfig: {
|
||||||
|
term: window.document.body.dataset.slug
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, 'https://giscus.app')
|
||||||
|
|
||||||
document.addEventListener("themechange", changeTheme)
|
document.addEventListener("themechange", changeTheme)
|
||||||
window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
|
window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
|
||||||
})
|
})`,
|
||||||
`
|
})
|
||||||
|
|
||||||
|
return <div class="giscus"></div>
|
||||||
|
}
|
||||||
|
|
||||||
return Comments
|
return Comments
|
||||||
}) satisfies QuartzComponentConstructor<Options>
|
}) satisfies QuartzComponentConstructor<Options>
|
||||||
|
Loading…
Reference in New Issue
Block a user