| | |
| | | import readingTime from "reading-time" |
| | | import { classNames } from "../util/lang" |
| | | import { i18n } from "../i18n" |
| | | import { JSX } from "preact" |
| | | import style from "./styles/contentMeta.scss" |
| | | |
| | | interface ContentMetaOptions { |
| | | /** |
| | | * Whether to display reading time |
| | | */ |
| | | showReadingTime: boolean |
| | | showComma: boolean |
| | | } |
| | | |
| | | const defaultOptions: ContentMetaOptions = { |
| | | showReadingTime: true, |
| | | showComma: true, |
| | | } |
| | | |
| | | export default ((opts?: Partial<ContentMetaOptions>) => { |
| | |
| | | const text = fileData.text |
| | | |
| | | if (text) { |
| | | const segments: string[] = [] |
| | | const segments: (string | JSX.Element)[] = [] |
| | | |
| | | if (fileData.dates) { |
| | | segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale)) |
| | |
| | | segments.push(displayedTime) |
| | | } |
| | | |
| | | return <p class={classNames(displayClass, "content-meta")}>{segments.join(", ")}</p> |
| | | const segmentsElements = segments.map((segment) => <span>{segment}</span>) |
| | | |
| | | return ( |
| | | <p show-comma={options.showComma} class={classNames(displayClass, "content-meta")}> |
| | | {segmentsElements} |
| | | </p> |
| | | ) |
| | | } else { |
| | | return null |
| | | } |
| | | } |
| | | |
| | | ContentMetadata.css = ` |
| | | .content-meta { |
| | | margin-top: 0; |
| | | color: var(--gray); |
| | | } |
| | | ` |
| | | ContentMetadata.css = style |
| | | |
| | | return ContentMetadata |
| | | }) satisfies QuartzComponentConstructor |