import { formatDate, getDate } from "./Date" import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import readingTime from "reading-time" import { classNames } from "../util/lang" import { JSX } from "preact/jsx-runtime" 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 const filepath = fileData.filePath if (text && filepath) { const fileRepoUrl: string = `${cfg.repoUrl}/commits/branch/v4/${filepath}` const segments: JSX.Element[] = [] // const segments: string[] = [] if (fileData.dates?.created) { segments.push(created: {formatDate(fileData.dates.created, cfg.locale)}) } if (fileData.dates?.modified) { segments.push( updated: {formatDate(fileData.dates.modified, cfg.locale)}) } // Display reading time if enabled if (options.showReadingTime) { const { text: timeTaken, words: _words } = readingTime(text) segments.push({timeTaken}) } segments.push( view history , ) return (

{segments.map((meta, idx) => ( <> {meta} ))}

) } else { return null } } ContentMetadata.css = ` .content-meta { margin-top: 0; color: var(--gray); } .content-meta span{ margin-right: 10px; } ` return ContentMetadata }) satisfies QuartzComponentConstructor