From c11395e7bcd75eef37b4f4e9c67dc9c6f912c0b7 Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Sat, 20 Jan 2024 22:18:35 +0100 Subject: [PATCH] feat: Add an option to display or not reading time from notes (#707) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add an option to display or not reading time from notes * Prettier (?) * Remove ContentMeta override from quartz.layout.ts * Make it positive ! 🌞 * Update quartz/components/ContentMeta.tsx --------- Co-authored-by: Jacky Zhao --- quartz/components/ContentMeta.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/quartz/components/ContentMeta.tsx b/quartz/components/ContentMeta.tsx index 21dc13f..254c5d4 100644 --- a/quartz/components/ContentMeta.tsx +++ b/quartz/components/ContentMeta.tsx @@ -2,18 +2,37 @@ import { formatDate, getDate } from "./Date" import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import readingTime from "reading-time" -export default (() => { +interface ContentMetaOptions { + /** + * Whether to display reading time + */ + showReadingTime: boolean +} + +const defaultOptions: ContentMetaOptions = { + showReadingTime: true, +} + +export default ((opts?: Partial) => { + // Merge options with defaults + const options: ContentMetaOptions = { ...defaultOptions, ...opts } + function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) { const text = fileData.text + if (text) { const segments: string[] = [] - const { text: timeTaken, words: _words } = readingTime(text) if (fileData.dates) { segments.push(formatDate(getDate(cfg, fileData)!)) } - segments.push(timeTaken) + // Display reading time if enabled + if (options.showReadingTime) { + const { text: timeTaken, words: _words } = readingTime(text) + segments.push(timeTaken) + } + return

{segments.join(", ")}

} else { return null