mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 10:54:06 -06:00
Merge 3ac2ea1327 into bacd19c4ea
This commit is contained in:
commit
d5f89a5cf5
@ -1,9 +1,13 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import script from "./scripts/comments.inline"
|
import giscusScript from "./scripts/comments.giscus.inline"
|
||||||
|
// @ts-ignore
|
||||||
|
import hyvorTalkScript from "./scripts/comments.hyvor_talk.inline"
|
||||||
|
|
||||||
type Options = {
|
type Options = GiscusOptions | HyvorTalkOptions
|
||||||
|
|
||||||
|
type GiscusOptions = {
|
||||||
provider: "giscus"
|
provider: "giscus"
|
||||||
options: {
|
options: {
|
||||||
repo: `${string}/${string}`
|
repo: `${string}/${string}`
|
||||||
@ -21,6 +25,13 @@ type Options = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HyvorTalkOptions = {
|
||||||
|
provider: "hyvor_talk"
|
||||||
|
options: {
|
||||||
|
websiteId: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function boolToStringBool(b: boolean): string {
|
function boolToStringBool(b: boolean): string {
|
||||||
return b ? "1" : "0"
|
return b ? "1" : "0"
|
||||||
}
|
}
|
||||||
@ -35,28 +46,36 @@ export default ((opts: Options) => {
|
|||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
if (opts.provider === "hyvor_talk") {
|
||||||
<div
|
return <div id="hyvor-talk-container" data-website-id={opts.options.websiteId}></div>
|
||||||
class={classNames(displayClass, "giscus")}
|
} else {
|
||||||
data-repo={opts.options.repo}
|
return (
|
||||||
data-repo-id={opts.options.repoId}
|
<div
|
||||||
data-category={opts.options.category}
|
class={classNames(displayClass, "giscus")}
|
||||||
data-category-id={opts.options.categoryId}
|
data-repo={opts.options.repo}
|
||||||
data-mapping={opts.options.mapping ?? "url"}
|
data-repo-id={opts.options.repoId}
|
||||||
data-strict={boolToStringBool(opts.options.strict ?? true)}
|
data-category={opts.options.category}
|
||||||
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
|
data-category-id={opts.options.categoryId}
|
||||||
data-input-position={opts.options.inputPosition ?? "bottom"}
|
data-mapping={opts.options.mapping ?? "url"}
|
||||||
data-light-theme={opts.options.lightTheme ?? "light"}
|
data-strict={boolToStringBool(opts.options.strict ?? true)}
|
||||||
data-dark-theme={opts.options.darkTheme ?? "dark"}
|
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
|
||||||
data-theme-url={
|
data-input-position={opts.options.inputPosition ?? "bottom"}
|
||||||
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
|
data-light-theme={opts.options.lightTheme ?? "light"}
|
||||||
}
|
data-dark-theme={opts.options.darkTheme ?? "dark"}
|
||||||
data-lang={opts.options.lang ?? "en"}
|
data-theme-url={
|
||||||
></div>
|
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
|
||||||
)
|
}
|
||||||
|
data-lang={opts.options.lang ?? "en"}
|
||||||
|
></div>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Comments.afterDOMLoaded = script
|
if (opts.provider === "hyvor_talk") {
|
||||||
|
Comments.afterDOMLoaded = hyvorTalkScript
|
||||||
|
} else {
|
||||||
|
Comments.afterDOMLoaded = giscusScript
|
||||||
|
}
|
||||||
|
|
||||||
return Comments
|
return Comments
|
||||||
}) satisfies QuartzComponentConstructor<Options>
|
}) satisfies QuartzComponentConstructor<Options>
|
||||||
|
|||||||
33
quartz/components/scripts/comments.hyvor_talk.inline.ts
Normal file
33
quartz/components/scripts/comments.hyvor_talk.inline.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
document.addEventListener("nav", () => {
|
||||||
|
if (!document.getElementById("hyvor-talk-script")) {
|
||||||
|
const script = document.createElement("script")
|
||||||
|
script.id = "hyvor-talk-script"
|
||||||
|
script.src = "https://talk.hyvor.com/embed/embed.js"
|
||||||
|
script.async = true
|
||||||
|
script.type = "module"
|
||||||
|
|
||||||
|
document.body.appendChild(script)
|
||||||
|
}
|
||||||
|
|
||||||
|
const container = document.getElementById("hyvor-talk-container")
|
||||||
|
if (!container) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const websiteId = container.dataset.websiteId
|
||||||
|
if (!websiteId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const comments = document.createElement("hyvor-talk-comments")
|
||||||
|
comments.setAttribute("website-id", websiteId)
|
||||||
|
comments.setAttribute("page-id", window.location.pathname)
|
||||||
|
comments.setAttribute("instance", "https://talk.hyvor.localhost")
|
||||||
|
|
||||||
|
if ((window as any).hyvorTalkStyles) {
|
||||||
|
;(window as any).hyvorTalkStyles.stylesheet = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
container.innerHTML = ""
|
||||||
|
container.appendChild(comments)
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user