feat: add post update date (#243)

* feat: Add article update date

* feat:
1.Hide update time on the homepage;
2.Replace update icon;

* remove iconify-json/mdi

---------

Co-authored-by: liangjianhao <jianhao.liang@sz-sanjiang.com>
This commit is contained in:
kinho
2024-12-04 19:29:35 +08:00
committed by GitHub
parent 079abbc965
commit b604cdf18c
6 changed files with 22 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ interface Props {
title: string title: string
url: string url: string
published: Date published: Date
updated?: Date
tags: string[] tags: string[]
category: string category: string
image: string image: string
@@ -25,6 +26,7 @@ const {
title, title,
url, url,
published, published,
updated,
tags, tags,
category, category,
image, image,
@@ -54,7 +56,7 @@ const { remarkPluginFrontmatter } = await entry.render()
</a> </a>
<!-- metadata --> <!-- metadata -->
<PostMetadata published={published} tags={tags} category={category} hideTagsForMobile={true} class="mb-4"></PostMetadata> <PostMetadata published={published} updated={updated} tags={tags} category={category} hideTagsForMobile={true} hideUpdateDate={true} class="mb-4"></PostMetadata>
<!-- description --> <!-- description -->
<div class:list={["transition text-75 mb-3.5 pr-4", {"line-clamp-2 md:line-clamp-1": !description}]}> <div class:list={["transition text-75 mb-3.5 pr-4", {"line-clamp-2 md:line-clamp-1": !description}]}>

View File

@@ -8,11 +8,13 @@ import { url } from '../utils/url-utils'
interface Props { interface Props {
class: string class: string
published: Date published: Date
updated?: Date
tags: string[] tags: string[]
category: string category: string
hideTagsForMobile?: boolean hideTagsForMobile?: boolean
hideUpdateDate?: boolean
} }
const { published, tags, category, hideTagsForMobile = false } = Astro.props const { published, updated, tags, category, hideTagsForMobile = false, hideUpdateDate = false } = Astro.props
const className = Astro.props.class const className = Astro.props.class
--- ---
@@ -26,6 +28,17 @@ const className = Astro.props.class
<span class="text-50 text-sm font-medium">{formatDateToYYYYMMDD(published)}</span> <span class="text-50 text-sm font-medium">{formatDateToYYYYMMDD(published)}</span>
</div> </div>
<!-- update date -->
{!hideUpdateDate && updated && updated.getTime() !== published.getTime() && (
<div class="flex items-center">
<div class="meta-icon"
>
<Icon name="material-symbols:edit-calendar-outline-rounded" class="text-xl"></Icon>
</div>
<span class="text-50 text-sm font-medium">{formatDateToYYYYMMDD(updated)}</span>
</div>
)}
<!-- categories --> <!-- categories -->
<div class="flex items-center"> <div class="flex items-center">
<div class="meta-icon" <div class="meta-icon"

View File

@@ -8,7 +8,7 @@ let delay = 0
const interval = 50 const interval = 50
--- ---
<div class="transition flex flex-col rounded-[var(--radius-large)] bg-[var(--card-bg)] py-1 md:py-0 md:bg-transparent md:gap-4 mb-4"> <div class="transition flex flex-col rounded-[var(--radius-large)] bg-[var(--card-bg)] py-1 md:py-0 md:bg-transparent md:gap-4 mb-4">
{page.data.map((entry: { data: { draft: boolean; title: string; tags: string[]; category: string; published: Date; image: string; description: string; }; slug: string; }) => { {page.data.map((entry: { data: { draft: boolean; title: string; tags: string[]; category: string; published: Date; image: string; description: string; updated: Date; }; slug: string; }) => {
return ( return (
<PostCard <PostCard
entry={entry} entry={entry}
@@ -16,6 +16,7 @@ const interval = 50
tags={entry.data.tags} tags={entry.data.tags}
category={entry.data.category} category={entry.data.category}
published={entry.data.published} published={entry.data.published}
updated={entry.data.updated}
url={getPostUrlBySlug(entry.slug)} url={getPostUrlBySlug(entry.slug)}
image={entry.data.image} image={entry.data.image}
description={entry.data.description} description={entry.data.description}

View File

@@ -4,6 +4,7 @@ const postsCollection = defineCollection({
schema: z.object({ schema: z.object({
title: z.string(), title: z.string(),
published: z.date(), published: z.date(),
updated: z.date().optional(),
draft: z.boolean().optional().default(false), draft: z.boolean().optional().default(false),
description: z.string().optional().default(''), description: z.string().optional().default(''),
image: z.string().optional().default(''), image: z.string().optional().default(''),

View File

@@ -1,6 +1,7 @@
--- ---
title: Markdown Extended Features title: Markdown Extended Features
published: 2024-05-01 published: 2024-05-01
updated: 2024-11-29
description: 'Read more about Markdown features in Fuwari' description: 'Read more about Markdown features in Fuwari'
image: '' image: ''
tags: [Demo, Example, Markdown, Fuwari] tags: [Demo, Example, Markdown, Fuwari]

View File

@@ -86,6 +86,7 @@ const jsonLd = {
<PostMetadata <PostMetadata
class="mb-5" class="mb-5"
published={entry.data.published} published={entry.data.published}
updated={entry.data.updated}
tags={entry.data.tags} tags={entry.data.tags}
category={entry.data.category} category={entry.data.category}
></PostMetadata> ></PostMetadata>