mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 06:44:07 -06:00
显示文章创建和修改时间
This commit is contained in:
parent
91c1e6035b
commit
a3f11f01e2
@ -29,19 +29,50 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
|
|||||||
if (text) {
|
if (text) {
|
||||||
const segments: (string | JSX.Element)[] = []
|
const segments: (string | JSX.Element)[] = []
|
||||||
|
|
||||||
if (fileData.dates) {
|
if (fileData.dates && fileData.slug !== "index") {
|
||||||
segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
|
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
|
// Display reading time if enabled
|
||||||
if (options.showReadingTime) {
|
if (options.showReadingTime) {
|
||||||
const { minutes, words: _words } = readingTime(text)
|
const { minutes, words: _words } = readingTime(text)
|
||||||
const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({
|
const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({
|
||||||
minutes: Math.ceil(minutes),
|
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>)
|
const segmentsElements = segments.map((segment) => <span>{segment}</span>)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -23,6 +23,8 @@ export function formatDate(d: Date, locale: ValidLocale = "en-US"): string {
|
|||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,7 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
|
|||||||
created ||= st.birthtimeMs
|
created ||= st.birthtimeMs
|
||||||
modified ||= st.mtimeMs
|
modified ||= st.mtimeMs
|
||||||
} else if (source === "frontmatter" && file.data.frontmatter) {
|
} else if (source === "frontmatter" && file.data.frontmatter) {
|
||||||
|
created ||= file.data.frontmatter.created as MaybeDate
|
||||||
created ||= file.data.frontmatter.date as MaybeDate
|
created ||= file.data.frontmatter.date as MaybeDate
|
||||||
modified ||= file.data.frontmatter.lastmod as MaybeDate
|
modified ||= file.data.frontmatter.lastmod as MaybeDate
|
||||||
modified ||= file.data.frontmatter.updated as MaybeDate
|
modified ||= file.data.frontmatter.updated as MaybeDate
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user