2023-08-24 22:56:40 +07:00
|
|
|
import { formatDate, getDate } from "./Date"
|
2023-08-09 11:28:09 +07:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
|
|
|
import readingTime from "reading-time"
|
|
|
|
|
|
|
|
export default (() => {
|
2023-08-24 22:56:40 +07:00
|
|
|
function ContentMetadata({ cfg, fileData }: QuartzComponentProps) {
|
2023-08-09 11:28:09 +07:00
|
|
|
const text = fileData.text
|
|
|
|
if (text) {
|
|
|
|
const segments: string[] = []
|
|
|
|
const { text: timeTaken, words: _words } = readingTime(text)
|
2023-08-24 22:56:40 +07:00
|
|
|
|
|
|
|
if (fileData.dates) {
|
|
|
|
segments.push(formatDate(getDate(cfg, fileData)!))
|
2023-08-09 11:28:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
segments.push(timeTaken)
|
2023-08-09 11:31:36 +07:00
|
|
|
return <p class="content-meta">{segments.join(", ")}</p>
|
2023-08-09 11:28:09 +07:00
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentMetadata.css = `
|
|
|
|
.content-meta {
|
|
|
|
margin-top: 0;
|
|
|
|
color: var(--gray);
|
|
|
|
}
|
|
|
|
`
|
|
|
|
return ContentMetadata
|
|
|
|
}) satisfies QuartzComponentConstructor
|