David Fischer
2024-11-09 31e0b7c6f802cfab7250b7e9dfb321b3889ef6ca
feat(comments): conditional display via frontmatter (#1566)

3 files modified
21 ■■■■■ changed files
docs/features/comments.md 11 ●●●●● patch | view | raw | blame | history
quartz/components/Comments.tsx 9 ●●●● patch | view | raw | blame | history
quartz/plugins/transformers/frontmatter.ts 1 ●●●● patch | view | raw | blame | history
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
---
```
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")}
quartz/plugins/transformers/frontmatter.ts
@@ -93,6 +93,7 @@
        lang: string
        enableToc: string
        cssclasses: string[]
        comments: boolean | string
      }>
  }
}