mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 04:56:23 +00:00
* fix comments on spa * fix giscus
This commit is contained in:
parent
e1a9661be7
commit
6264f5685c
3 changed files with 28 additions and 27 deletions
|
@ -20,7 +20,26 @@ 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) => <div class="giscus"></div>
|
||||||
|
|
||||||
Comments.afterDOMLoaded = `
|
Comments.afterDOMLoaded = `
|
||||||
|
const changeTheme = (e) => {
|
||||||
|
const theme = e.detail.theme
|
||||||
|
const iframe = document.querySelector('iframe.giscus-frame')
|
||||||
|
if (!iframe) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
iframe.contentWindow.postMessage({
|
||||||
|
giscus: {
|
||||||
|
setConfig: {
|
||||||
|
theme: theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 'https://giscus.app')
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("nav", () => {
|
||||||
|
const giscusContainer = document.querySelector(".giscus")
|
||||||
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
|
||||||
|
@ -38,29 +57,11 @@ export default ((opts: Options) => {
|
||||||
|
|
||||||
const theme = document.documentElement.getAttribute("saved-theme")
|
const theme = document.documentElement.getAttribute("saved-theme")
|
||||||
giscusScript.setAttribute("data-theme", theme)
|
giscusScript.setAttribute("data-theme", theme)
|
||||||
document.head.appendChild(giscusScript)
|
giscusContainer.appendChild(giscusScript)
|
||||||
|
|
||||||
const changeTheme = (e) => {
|
document.addEventListener("themechange", changeTheme)
|
||||||
const theme = e.detail.theme
|
window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
|
||||||
const iframe = document.querySelector('iframe.giscus-frame')
|
})`
|
||||||
if (!iframe) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
iframe.contentWindow.postMessage({
|
|
||||||
giscus: {
|
|
||||||
setConfig: {
|
|
||||||
theme: theme
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 'https://giscus.app')
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
|
||||||
document.addEventListener("themechange", changeTheme)
|
|
||||||
window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
|
|
||||||
})
|
|
||||||
`
|
|
||||||
|
|
||||||
return Comments
|
return Comments
|
||||||
}) satisfies QuartzComponentConstructor<Options>
|
}) satisfies QuartzComponentConstructor<Options>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { ContentDetails, ContentIndex } from "../../plugins/emitters/contentIndex"
|
import type { ContentDetails } from "../../plugins/emitters/contentIndex"
|
||||||
import * as d3 from "d3"
|
import * as d3 from "d3"
|
||||||
import { registerEscapeHandler, removeAllChildren } from "./util"
|
import { registerEscapeHandler, removeAllChildren } from "./util"
|
||||||
import { FullSlug, SimpleSlug, getFullSlug, resolveRelative, simplifySlug } from "../../util/path"
|
import { FullSlug, SimpleSlug, getFullSlug, resolveRelative, simplifySlug } from "../../util/path"
|
||||||
|
|
|
@ -28,10 +28,10 @@ export function getStaticResourcesFromPlugins(ctx: BuildCtx) {
|
||||||
loadTime: "afterDOMReady",
|
loadTime: "afterDOMReady",
|
||||||
contentType: "inline",
|
contentType: "inline",
|
||||||
script: `
|
script: `
|
||||||
const socket = new WebSocket('${wsUrl}')
|
const socket = new WebSocket('${wsUrl}')
|
||||||
// reload(true) ensures resources like images and scripts are fetched again in firefox
|
// reload(true) ensures resources like images and scripts are fetched again in firefox
|
||||||
socket.addEventListener('message', () => document.location.reload(true))
|
socket.addEventListener('message', () => document.location.reload(true))
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue