Skip to content

Commit becce15

Browse files
vanrensbirdclaudeankur-arch
authored
Show updated date on blog post cards (#8013)
Thread an optional updatedAt field from post frontmatter through the card builders to the PostCard UI, rendering "Updated {date}" alongside the original publish date (separated by a "|" when both are present). Surfaces refresh dates on the series and home listings. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Ankur Datta <64993082+ankur-arch@users.noreply.github.com>
1 parent 2212ee6 commit becce15

6 files changed

Lines changed: 39 additions & 0 deletions

File tree

apps/blog/src/app/(blog)/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,21 @@ export default async function BlogHome() {
9090
}
9191
}
9292

93+
let updatedAtISO: string | null = null;
94+
if (data.updatedAt) {
95+
const updatedObj = new Date(data.updatedAt);
96+
if (!isNaN(updatedObj.getTime())) {
97+
updatedAtISO = updatedObj.toISOString();
98+
}
99+
}
100+
93101
const authors = getAllAuthors(post);
94102

95103
return {
96104
url: withBlogBasePath(post.url),
97105
title: data.title as string,
98106
date: dateISO,
107+
updatedAt: updatedAtISO,
99108
excerpt: data.metaDescription as string,
100109
author: authors[0] ?? null,
101110
authors,

apps/blog/src/app/(blog)/series/[key]/page.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function buildCardItems(seriesKey: string): BlogCardItem[] {
2121
const data = post.data as {
2222
title?: string;
2323
date?: Date | string;
24+
updatedAt?: Date | string;
2425
metaDescription?: string;
2526
authors?: string[];
2627
heroImagePath?: string;
@@ -36,6 +37,14 @@ function buildCardItems(seriesKey: string): BlogCardItem[] {
3637
}
3738
}
3839

40+
let updatedAtISO: string | null = null;
41+
if (data.updatedAt) {
42+
const updatedObj = new Date(data.updatedAt);
43+
if (!Number.isNaN(updatedObj.getTime())) {
44+
updatedAtISO = updatedObj.toISOString();
45+
}
46+
}
47+
3948
const authors = Array.isArray(data.authors)
4049
? data.authors.filter((a): a is string => typeof a === "string")
4150
: [];
@@ -44,6 +53,7 @@ function buildCardItems(seriesKey: string): BlogCardItem[] {
4453
url: withBlogBasePath(post.url),
4554
title: data.title ?? "",
4655
date: dateISO,
56+
updatedAt: updatedAtISO,
4757
excerpt: data.metaDescription,
4858
author: authors[0] ?? null,
4959
authors,

apps/blog/src/components/BlogGrid.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type BlogCardItem = {
44
url: string;
55
title: string;
66
date: string; // ISO string
7+
updatedAt?: string | null; // ISO string
78
excerpt?: string | null;
89
author?: string | null;
910
authors?: string[] | null;

apps/blog/src/components/PostCard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type PostCardItem = {
1313
url: string;
1414
title: string;
1515
date: string;
16+
updatedAt?: string | null;
1617
excerpt?: string | null;
1718
author?: string | null;
1819
authors?: string[] | null;
@@ -50,6 +51,7 @@ export function PostCard({
5051
url: post.url,
5152
title: post.title,
5253
date: formatDate(new Date(post.date).toISOString()),
54+
updatedAt: post.updatedAt ? formatDate(new Date(post.updatedAt).toISOString()) : null,
5355
excerpt: post.excerpt,
5456
author,
5557
authors: authorProfiles,

apps/blog/src/lib/post-card-item.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ export function toBlogCardItem(page: BlogPage): BlogCardItem {
2626
heroImagePath?: string;
2727
heroImageAlt?: string;
2828
tags?: string[];
29+
updatedAt?: Date | string;
2930
};
3031
const authors = Array.isArray(data.authors)
3132
? data.authors.filter((name): name is string => typeof name === "string")
3233
: [];
3334
const time = getPostTime(page);
3435

36+
let updatedAtISO: string | null = null;
37+
if (data.updatedAt) {
38+
const updated = new Date(data.updatedAt);
39+
if (!Number.isNaN(updated.getTime())) updatedAtISO = updated.toISOString();
40+
}
41+
3542
return {
3643
url: withBlogBasePath(page.url),
3744
title: data.title ?? "",
3845
date: time ? new Date(time).toISOString() : "",
46+
updatedAt: updatedAtISO,
3947
excerpt: data.metaDescription ?? null,
4048
author: authors[0] ?? null,
4149
authors,

packages/ui/src/components/post-card.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type PostCardItem = {
88
url: string;
99
title: string;
1010
date: string;
11+
updatedAt?: string | null;
1112
excerpt?: string | null;
1213
author?: AuthorProfile | null;
1314
authors?: AuthorProfile[] | null;
@@ -64,6 +65,14 @@ export function PostCard({
6465
<div className="eyebrow flex gap-2 items-center">
6566
{post.badge && <Badge color="success" label={post.badge} className="w-fit text-xs" />}
6667
{post.date && <span className="text-xs text-foreground-neutral-weak">{post.date}</span>}
68+
{post.date && post.updatedAt && (
69+
<span className="text-xs text-foreground-neutral-weak" aria-hidden="true">
70+
|
71+
</span>
72+
)}
73+
{post.updatedAt && (
74+
<span className="text-xs text-foreground-neutral-weak">Updated {post.updatedAt}</span>
75+
)}
6776
</div>
6877
{post.title && <h2 className={titleClassName}>{post.title}</h2>}
6978
{post.excerpt && <p className={excerptClassName}>{post.excerpt}</p>}

0 commit comments

Comments
 (0)