From b604cdf18cd6a9bb5361b9df7c4c7aed68783555 Mon Sep 17 00:00:00 2001 From: kinho <109323159+KinhoLeung@users.noreply.github.com> Date: Wed, 4 Dec 2024 19:29:35 +0800 Subject: [PATCH] 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 --- src/components/PostCard.astro | 4 +++- src/components/PostMeta.astro | 15 ++++++++++++++- src/components/PostPage.astro | 3 ++- src/content/config.ts | 1 + src/content/posts/markdown-extended.md | 1 + src/pages/posts/[...slug].astro | 1 + 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro index 5ae303e8..a175f764 100644 --- a/src/components/PostCard.astro +++ b/src/components/PostCard.astro @@ -13,6 +13,7 @@ interface Props { title: string url: string published: Date + updated?: Date tags: string[] category: string image: string @@ -25,6 +26,7 @@ const { title, url, published, + updated, tags, category, image, @@ -54,7 +56,7 @@ const { remarkPluginFrontmatter } = await entry.render() - +
diff --git a/src/components/PostMeta.astro b/src/components/PostMeta.astro index bcc38e8b..3d166ff0 100644 --- a/src/components/PostMeta.astro +++ b/src/components/PostMeta.astro @@ -8,11 +8,13 @@ import { url } from '../utils/url-utils' interface Props { class: string published: Date + updated?: Date tags: string[] category: string 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 --- @@ -26,6 +28,17 @@ const className = Astro.props.class {formatDateToYYYYMMDD(published)}
+ + {!hideUpdateDate && updated && updated.getTime() !== published.getTime() && ( +
+
+ +
+ {formatDateToYYYYMMDD(updated)} +
+ )} +
- {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 (