Skip to content

Commit 9c4e098

Browse files
committed
show last updated date
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
1 parent 9e265d8 commit 9c4e098

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/content.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const articles = defineCollection({
1313
hero_image_credit_text: z.string().optional(),
1414
path: z.string(),
1515
date: z.coerce.date(),
16+
dateModified: z.coerce.date().optional(),
1617
keywords: z.string(),
1718
tags: z.array(z.string()),
1819
category: z.enum(['General', 'Technology', 'Photography', 'Engineering and Development', 'Philosophy', 'Muse']).optional(),

src/layouts/article.astro

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ const date = new Date(content.date).toLocaleDateString("en-us", {
1717
day: "numeric",
1818
});
1919
20+
const dateModified = content.dateModified ? new Date(content.dateModified).toLocaleDateString("en-us", {
21+
year: "numeric",
22+
month: "long",
23+
day: "numeric",
24+
}) : null;
25+
26+
const hasBeenUpdated = content.dateModified && content.dateModified !== content.date;
27+
2028
const isoDate = content.date ? new Date(content.date).toISOString() : "";
29+
const isoDateModified = content.dateModified ? new Date(content.dateModified).toISOString() : isoDate;
2130
const articleUrl = new URL(
2231
content.path || Astro.url.pathname,
2332
Astro.site || "https://rishikc.com",
@@ -39,7 +48,7 @@ const imageUrl = content.hero_image?.src
3948
description: content.description,
4049
image: imageUrl,
4150
datePublished: isoDate,
42-
dateModified: isoDate,
51+
dateModified: isoDateModified,
4352
author: {
4453
"@type": "Person",
4554
name: profile.name,
@@ -102,12 +111,53 @@ const imageUrl = content.hero_image?.src
102111
)
103112
}
104113
</div>
105-
<small
114+
<div
106115
transition:name={`${content.path}-date`}
107-
class="justify-start text-gray-600 text-center text-sm font-normal font-['Montserrat_Variable'] leading-tight mb-8"
116+
class="inline-flex items-center gap-3 mb-8 flex-wrap justify-center"
108117
>
109-
{date}
110-
</small>
118+
<div class="inline-flex items-center gap-1.5 px-3 py-1 bg-gray-100 rounded-full">
119+
<svg
120+
xmlns="http://www.w3.org/2000/svg"
121+
class="h-3.5 w-3.5 text-gray-600"
122+
fill="none"
123+
viewBox="0 0 24 24"
124+
stroke="currentColor"
125+
stroke-width="2"
126+
>
127+
<path
128+
stroke-linecap="round"
129+
stroke-linejoin="round"
130+
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
131+
></path>
132+
</svg>
133+
<small class="text-gray-700 text-xs font-medium font-['Montserrat_Variable'] leading-tight">
134+
{date}
135+
</small>
136+
</div>
137+
{
138+
hasBeenUpdated && (
139+
<div class="inline-flex items-center gap-1.5 px-3 py-1 bg-brand-50 rounded-full">
140+
<svg
141+
xmlns="http://www.w3.org/2000/svg"
142+
class="h-3.5 w-3.5 text-brand-600"
143+
fill="none"
144+
viewBox="0 0 24 24"
145+
stroke="currentColor"
146+
stroke-width="2"
147+
>
148+
<path
149+
stroke-linecap="round"
150+
stroke-linejoin="round"
151+
d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
152+
></path>
153+
</svg>
154+
<small class="text-brand-700 text-xs font-medium font-['Montserrat_Variable'] leading-tight">
155+
Updated {dateModified}
156+
</small>
157+
</div>
158+
)
159+
}
160+
</div>
111161
<div class="w-full md:max-w-[790px] mb-10">
112162
<Image
113163
class="w-full rounded-xl shadow-md"

0 commit comments

Comments
 (0)