Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comments): add conditional display using frontmatter #1566

Open
wants to merge 5 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/features/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ afterBody: [
}),
],
```

#### 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
---
```
9 changes: 8 additions & 1 deletion quartz/components/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ function boolToStringBool(b: boolean): string {
}

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")}
Expand Down
1 change: 1 addition & 0 deletions quartz/plugins/transformers/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ declare module "vfile" {
lang: string
enableToc: string
cssclasses: string[]
comments: boolean | string
}>
}
}