显示文章创建和修改时间

This commit is contained in:
wangzipai 2024-10-30 15:59:04 +08:00
parent 91c1e6035b
commit a3f11f01e2
3 changed files with 37 additions and 3 deletions

View File

@ -29,19 +29,50 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
if (text) {
const segments: (string | JSX.Element)[] = []
if (fileData.dates) {
segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
if (fileData.dates && fileData.slug !== "index") {
if (fileData.dates.created) {
segments.push(
<span>
<svg xmlns="http://www.w3.org/2000/svg" style="position:relative; top:2px;" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar-plus"><path d="M8 2v4"/><path d="M16 2v4"/><path d="M21 13V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8"/><path d="M3 10h18"/><path d="M16 19h6"/><path d="M19 16v6"/></svg> {formatDate(fileData.dates.created,cfg.locale)}
</span>,
)
}
if (fileData.dates.modified) {
segments.push(
<span>
<svg xmlns="http://www.w3.org/2000/svg" style="position:relative; top:2px;" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar-clock"><path d="M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5"/><path d="M16 2v4"/><path d="M8 2v4"/><path d="M3 10h5"/><path d="M17.5 17.5 16 16.3V14"/><circle cx="16" cy="16" r="6"/></svg> {formatDate(fileData.dates.modified,cfg.locale)}
</span>,
)
}
}
// if (fileData.dates) {
// segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
// }
// Display reading time if enabled
if (options.showReadingTime) {
const { minutes, words: _words } = readingTime(text)
const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({
minutes: Math.ceil(minutes),
})
segments.push(displayedTime)
segments.push(
<span>
<svg xmlns="http://www.w3.org/2000/svg" style="position:relative; top:2px;" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-hourglass"><path d="M5 22h14"/><path d="M5 2h14"/><path d="M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22"/><path d="M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2"/></svg> {displayedTime}
</span>)
// segments.push(displayedTime)
}
segments.push(
<a
href={`https://github.githistory.xyz/qwqw3qee/quartz/commits/v4/${fileData.filePath}`}
target="_blank"
>
<svg xmlns="http://www.w3.org/2000/svg" style="position:relative; top:2px;" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-history"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/></svg>
</a>,
)
const segmentsElements = segments.map((segment) => <span>{segment}</span>)
return (

View File

@ -23,6 +23,8 @@ export function formatDate(d: Date, locale: ValidLocale = "en-US"): string {
year: "numeric",
month: "short",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
})
}

View File

@ -48,6 +48,7 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
created ||= st.birthtimeMs
modified ||= st.mtimeMs
} else if (source === "frontmatter" && file.data.frontmatter) {
created ||= file.data.frontmatter.created as MaybeDate
created ||= file.data.frontmatter.date as MaybeDate
modified ||= file.data.frontmatter.lastmod as MaybeDate
modified ||= file.data.frontmatter.updated as MaybeDate