mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 13:06:22 +00:00
feat: Add an option to display or not reading time from notes (#707)
* 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 <j.zhao2k19@gmail.com>
This commit is contained in:
parent
1f2ea96ae0
commit
c11395e7bc
1 changed files with 22 additions and 3 deletions
|
@ -2,18 +2,37 @@ import { formatDate, getDate } from "./Date"
|
||||||
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import readingTime from "reading-time"
|
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<ContentMetaOptions>) => {
|
||||||
|
// Merge options with defaults
|
||||||
|
const options: ContentMetaOptions = { ...defaultOptions, ...opts }
|
||||||
|
|
||||||
function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) {
|
function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) {
|
||||||
const text = fileData.text
|
const text = fileData.text
|
||||||
|
|
||||||
if (text) {
|
if (text) {
|
||||||
const segments: string[] = []
|
const segments: string[] = []
|
||||||
const { text: timeTaken, words: _words } = readingTime(text)
|
|
||||||
|
|
||||||
if (fileData.dates) {
|
if (fileData.dates) {
|
||||||
segments.push(formatDate(getDate(cfg, fileData)!))
|
segments.push(formatDate(getDate(cfg, fileData)!))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display reading time if enabled
|
||||||
|
if (options.showReadingTime) {
|
||||||
|
const { text: timeTaken, words: _words } = readingTime(text)
|
||||||
segments.push(timeTaken)
|
segments.push(timeTaken)
|
||||||
|
}
|
||||||
|
|
||||||
return <p class={`content-meta ${displayClass ?? ""}`}>{segments.join(", ")}</p>
|
return <p class={`content-meta ${displayClass ?? ""}`}>{segments.join(", ")}</p>
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in a new issue