* fix comments on spa * fix giscus
This commit is contained in:
parent
e1a9661be7
commit
6264f5685c
@ -20,26 +20,8 @@ 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 giscusScript = document.createElement("script")
|
|
||||||
giscusScript.src = "https://giscus.app/client.js"
|
|
||||||
giscusScript.async = true
|
|
||||||
giscusScript.crossOrigin = "anonymous"
|
|
||||||
giscusScript.setAttribute("data-loading", "lazy")
|
|
||||||
giscusScript.setAttribute("data-emit-metadata", "0")
|
|
||||||
giscusScript.setAttribute("data-repo", "${opts.options.repo}")
|
|
||||||
giscusScript.setAttribute("data-repo-id", "${opts.options.repoId}")
|
|
||||||
giscusScript.setAttribute("data-category", "${opts.options.category}")
|
|
||||||
giscusScript.setAttribute("data-category-id", "${opts.options.categoryId}")
|
|
||||||
giscusScript.setAttribute("data-mapping", "${opts.options.mapping ?? "url"}")
|
|
||||||
giscusScript.setAttribute("data-strict", "${boolToStringBool(opts.options.strict ?? true)}")
|
|
||||||
giscusScript.setAttribute("data-reactions-enabled", "${boolToStringBool(opts.options.reactionsEnabled ?? true)}")
|
|
||||||
giscusScript.setAttribute("data-input-position", "${opts.options.inputPosition ?? "bottom"}")
|
|
||||||
|
|
||||||
const theme = document.documentElement.getAttribute("saved-theme")
|
|
||||||
giscusScript.setAttribute("data-theme", theme)
|
|
||||||
document.head.appendChild(giscusScript)
|
|
||||||
|
|
||||||
const changeTheme = (e) => {
|
const changeTheme = (e) => {
|
||||||
const theme = e.detail.theme
|
const theme = e.detail.theme
|
||||||
const iframe = document.querySelector('iframe.giscus-frame')
|
const iframe = document.querySelector('iframe.giscus-frame')
|
||||||
@ -57,10 +39,29 @@ export default ((opts: Options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
|
const giscusContainer = document.querySelector(".giscus")
|
||||||
|
const giscusScript = document.createElement("script")
|
||||||
|
giscusScript.src = "https://giscus.app/client.js"
|
||||||
|
giscusScript.async = true
|
||||||
|
giscusScript.crossOrigin = "anonymous"
|
||||||
|
giscusScript.setAttribute("data-loading", "lazy")
|
||||||
|
giscusScript.setAttribute("data-emit-metadata", "0")
|
||||||
|
giscusScript.setAttribute("data-repo", "${opts.options.repo}")
|
||||||
|
giscusScript.setAttribute("data-repo-id", "${opts.options.repoId}")
|
||||||
|
giscusScript.setAttribute("data-category", "${opts.options.category}")
|
||||||
|
giscusScript.setAttribute("data-category-id", "${opts.options.categoryId}")
|
||||||
|
giscusScript.setAttribute("data-mapping", "${opts.options.mapping ?? "url"}")
|
||||||
|
giscusScript.setAttribute("data-strict", "${boolToStringBool(opts.options.strict ?? true)}")
|
||||||
|
giscusScript.setAttribute("data-reactions-enabled", "${boolToStringBool(opts.options.reactionsEnabled ?? true)}")
|
||||||
|
giscusScript.setAttribute("data-input-position", "${opts.options.inputPosition ?? "bottom"}")
|
||||||
|
|
||||||
|
const theme = document.documentElement.getAttribute("saved-theme")
|
||||||
|
giscusScript.setAttribute("data-theme", theme)
|
||||||
|
giscusContainer.appendChild(giscusScript)
|
||||||
|
|
||||||
document.addEventListener("themechange", changeTheme)
|
document.addEventListener("themechange", changeTheme)
|
||||||
window.addCleanup(() => document.removeEventListener("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"
|
||||||
|
Loading…
Reference in New Issue
Block a user