merge
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
import { formatDate, getDate } from "./Date"
|
||||
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import readingTime from "reading-time"
|
||||
import { classNames } from "../util/lang"
|
||||
|
||||
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 }
|
||||
|
||||
export default (() => {
|
||||
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('created: ' + formatDate(fileData.dates?.["created"]))
|
||||
segments.push('last updated: ' + formatDate(fileData.dates?.["modified"]))
|
||||
segments.push('last updated: ' + formatDate(fileData.dates?.["modified"], cfg.locale))
|
||||
}
|
||||
|
||||
segments.push(timeTaken)
|
||||
return <p class={`content-meta ${displayClass ?? ""}`}>{segments.join(", ")}</p>
|
||||
// Display reading time if enabled
|
||||
if (options.showReadingTime) {
|
||||
const { text: timeTaken, words: _words } = readingTime(text)
|
||||
segments.push(timeTaken)
|
||||
}
|
||||
|
||||
return <p class={classNames(displayClass, "content-meta")}>{segments.join(", ")}</p>
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user