2024-07-21 06:05:45 +00:00
|
|
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
2024-08-05 19:17:11 +00:00
|
|
|
import { classNames } from "../util/lang"
|
|
|
|
// @ts-ignore
|
|
|
|
import script from "./scripts/comments.inline"
|
2024-07-21 06:05:45 +00:00
|
|
|
|
|
|
|
type Options = {
|
|
|
|
provider: "giscus"
|
|
|
|
options: {
|
|
|
|
repo: `${string}/${string}`
|
|
|
|
repoId: string
|
|
|
|
category: string
|
|
|
|
categoryId: string
|
2024-10-17 22:30:16 +00:00
|
|
|
themeUrl?: string
|
|
|
|
lightTheme?: string
|
|
|
|
darkTheme?: string
|
2024-07-21 06:05:45 +00:00
|
|
|
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
|
|
|
strict?: boolean
|
|
|
|
reactionsEnabled?: boolean
|
|
|
|
inputPosition?: "top" | "bottom"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function boolToStringBool(b: boolean): string {
|
|
|
|
return b ? "1" : "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ((opts: Options) => {
|
2024-08-05 19:17:11 +00:00
|
|
|
const Comments: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={classNames(displayClass, "giscus")}
|
|
|
|
data-repo={opts.options.repo}
|
|
|
|
data-repo-id={opts.options.repoId}
|
|
|
|
data-category={opts.options.category}
|
|
|
|
data-category-id={opts.options.categoryId}
|
|
|
|
data-mapping={opts.options.mapping ?? "url"}
|
|
|
|
data-strict={boolToStringBool(opts.options.strict ?? true)}
|
|
|
|
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
|
|
|
|
data-input-position={opts.options.inputPosition ?? "bottom"}
|
2024-10-17 22:30:16 +00:00
|
|
|
data-light-theme={opts.options.lightTheme ?? "light"}
|
|
|
|
data-dark-theme={opts.options.darkTheme ?? "dark"}
|
|
|
|
data-theme-url={
|
|
|
|
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
|
|
|
|
}
|
2024-08-05 19:17:11 +00:00
|
|
|
></div>
|
|
|
|
)
|
|
|
|
}
|
2024-07-21 06:05:45 +00:00
|
|
|
|
2024-08-05 19:17:11 +00:00
|
|
|
Comments.afterDOMLoaded = script
|
2024-07-21 06:05:45 +00:00
|
|
|
|
|
|
|
return Comments
|
|
|
|
}) satisfies QuartzComponentConstructor<Options>
|