From 31e0b7c6f802cfab7250b7e9dfb321b3889ef6ca Mon Sep 17 00:00:00 2001
From: David Fischer <david@konst.fish>
Date: Sat, 09 Nov 2024 09:44:32 +0000
Subject: [PATCH] feat(comments): conditional display via frontmatter (#1566)
---
quartz/components/Comments.tsx | 9 ++++++++-
quartz/plugins/transformers/frontmatter.ts | 1 +
docs/features/comments.md | 11 +++++++++++
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/docs/features/comments.md b/docs/features/comments.md
index 1f11eff..4803773 100644
--- a/docs/features/comments.md
+++ b/docs/features/comments.md
@@ -114,3 +114,14 @@
}),
],
```
+
+#### Conditionally display comments
+
+Quartz can conditionally display the comment box based on a field `comments` in the frontmatter. By default, all pages will display comments, to disable it for a specific page, set `comments` to `false`.
+
+```
+---
+title: Comments disabled here!
+comments: false
+---
+```
diff --git a/quartz/components/Comments.tsx b/quartz/components/Comments.tsx
index 44331cc..5f379a1 100644
--- a/quartz/components/Comments.tsx
+++ b/quartz/components/Comments.tsx
@@ -25,7 +25,14 @@
}
export default ((opts: Options) => {
- const Comments: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
+ const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {
+ // check if comments should be displayed according to frontmatter
+ const commentsFlag: boolean =
+ fileData.frontmatter?.comments === true || fileData.frontmatter?.comments === "true"
+ if (!commentsFlag) {
+ return <></>
+ }
+
return (
<div
class={classNames(displayClass, "giscus")}
diff --git a/quartz/plugins/transformers/frontmatter.ts b/quartz/plugins/transformers/frontmatter.ts
index 2e599aa..cf3880e 100644
--- a/quartz/plugins/transformers/frontmatter.ts
+++ b/quartz/plugins/transformers/frontmatter.ts
@@ -93,6 +93,7 @@
lang: string
enableToc: string
cssclasses: string[]
+ comments: boolean | string
}>
}
}
--
Gitblit v1.10.0