diff --git a/quartz.config.ts b/quartz.config.ts
index e96ee4843fda1..9f1e4076081af 100644
--- a/quartz.config.ts
+++ b/quartz.config.ts
@@ -52,6 +52,9 @@ const config: QuartzConfig = {
},
},
},
+ comments: {
+ provider: "giscus",
+ },
},
plugins: {
transformers: [
diff --git a/quartz/cfg.ts b/quartz/cfg.ts
index 85527a093c410..3bf6d551260c8 100644
--- a/quartz/cfg.ts
+++ b/quartz/cfg.ts
@@ -43,6 +43,31 @@ export type Analytics =
projectId?: string
}
+export type Comments =
+ | null
+ | {
+ provider: "giscus"
+ repo: `${string}/${string}`
+ repoId: string
+ category: string
+ categoryId: string
+ mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
+ strict?: boolean
+ reactionsEnabled?: boolean
+ inputPosition?: "top" | "bottom"
+ }
+ | {
+ provider: "commento"
+ host?: string
+ cssOverride?: string
+ noFonts?: boolean
+ hideDeleted?: boolean
+ }
+ | {
+ provider: "disqus"
+ shortName: string
+ }
+
export interface GlobalConfiguration {
pageTitle: string
pageTitleSuffix?: string
diff --git a/quartz/components/Comments.tsx b/quartz/components/Comments.tsx
index 8e449402683c1..f43bc3acfc926 100644
--- a/quartz/components/Comments.tsx
+++ b/quartz/components/Comments.tsx
@@ -3,39 +3,50 @@ import { classNames } from "../util/lang"
// @ts-ignore
import script from "./scripts/comments.inline"
-type Options = {
- provider: "giscus"
- options: {
- repo: `${string}/${string}`
- repoId: string
- category: string
- categoryId: string
- 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) => {
+export default (() => {
const Comments: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
- return (
-
- )
+ switch (cfg.comments?.provider) {
+ case "giscus":
+ return (
+
+ )
+ case "commento":
+ return (
+
+ )
+ case "disqus":
+ return (
+
+ )
+ default:
+ return <>>
+ }
}
Comments.afterDOMLoaded = script
diff --git a/quartz/components/scripts/comments.inline.ts b/quartz/components/scripts/comments.inline.ts
index 4ab29f087cc08..4c4f16eb4c470 100644
--- a/quartz/components/scripts/comments.inline.ts
+++ b/quartz/components/scripts/comments.inline.ts
@@ -1,4 +1,4 @@
-const changeTheme = (e: CustomEventMap["themechange"]) => {
+const changeGiscusTheme = (e: CustomEventMap["themechange"]) => {
const theme = e.detail.theme
const iframe = document.querySelector("iframe.giscus-frame") as HTMLIFrameElement
if (!iframe) {
@@ -34,7 +34,7 @@ type GiscusElement = Omit & {
}
}
-document.addEventListener("nav", () => {
+function setupGiscus() {
const giscusContainer = document.querySelector(".giscus") as GiscusElement
if (!giscusContainer) {
return
@@ -62,6 +62,66 @@ document.addEventListener("nav", () => {
giscusContainer.appendChild(giscusScript)
- document.addEventListener("themechange", changeTheme)
- window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
+ document.addEventListener("themechange", changeGiscusTheme)
+ window.addCleanup(() => document.removeEventListener("themechange", changeGiscusTheme))
+}
+
+type CommentoElement = Omit & {
+ dataset: DOMStringMap & {
+ host: string
+ cssOverride: string
+ noFonts: string
+ hideDeleted: string
+ }
+}
+
+function setupCommento() {
+ const commentoContainer = document.querySelector("#commento") as CommentoElement
+ if (!commentoContainer) {
+ return
+ }
+
+ const commentoScript = document.createElement("script")
+ commentoScript.src = "https://" + commentoContainer.dataset.host + "/js/commento.js"
+ commentoScript.defer = true
+ commentoScript.setAttribute("data-css-override", commentoContainer.dataset.cssOverride)
+ commentoScript.setAttribute("data-no-fonts", commentoContainer.dataset.noFonts)
+ commentoScript.setAttribute("data-hide-deleted", commentoContainer.dataset.hideDeleted)
+
+ commentoContainer.appendChild(commentoScript)
+}
+
+type DisqusElement = Omit & {
+ dataset: DOMStringMap & {
+ shortName: string
+ }
+}
+
+function setupDisqus() {
+ const disqusContainer = document.querySelector("#disqus_thread")
+ if (!disqusContainer) {
+ return
+ }
+
+ const disqusScript = document.createElement("script")
+ disqusScript.src = "https://" + disqusContainer.dataset.shortName + ".disqus.com/embed.js"
+ disqusScript.setAttribute("data-timestamp", +new Date())
+
+ disqusContainer.appendChild(disqusScript)
+}
+
+document.addEventListener("nav", () => {
+ const commentContainer = document.querySelector("#comment")
+ if (!commentContainer) {
+ return
+ }
+ const provider = commentContainer.getAttribute("data-provider")
+ switch (provider) {
+ case "giscus":
+ setupGiscus()
+ case "commento":
+ setupCommento()
+ case "disqus":
+ setupDisqus()
+ }
})