feat(comments): conditional display via frontmatter (#1566)
This commit is contained in:
		
							parent
							
								
									a6b2967df8
								
							
						
					
					
						commit
						31e0b7c6f8
					
				| @ -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 | ||||||
|  | --- | ||||||
|  | ``` | ||||||
|  | |||||||
| @ -25,7 +25,14 @@ function boolToStringBool(b: boolean): string { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default ((opts: Options) => { | 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 ( |     return ( | ||||||
|       <div |       <div | ||||||
|         class={classNames(displayClass, "giscus")} |         class={classNames(displayClass, "giscus")} | ||||||
|  | |||||||
| @ -93,6 +93,7 @@ declare module "vfile" { | |||||||
|         lang: string |         lang: string | ||||||
|         enableToc: string |         enableToc: string | ||||||
|         cssclasses: string[] |         cssclasses: string[] | ||||||
|  |         comments: boolean | string | ||||||
|       }> |       }> | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user