Skip to content

Commit a32a042

Browse files
committed
Fix datePublished property in blog posts and update sorting logic
1 parent d54f107 commit a32a042

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/pages/blog.astro

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { getCollection } from "astro:content";
77
const allPosts = await getCollection("blog");
88
const sortedPosts = allPosts.sort(
99
(a, b) =>
10-
new Date(b.data.pubDate).valueOf() - new Date(a.data.pubDate).valueOf(),
10+
new Date(b.data.datePublished).valueOf() -
11+
new Date(a.data.datePublished).valueOf(),
1112
);
1213
1314
const pageTitle = "Blog Posts";
@@ -42,16 +43,15 @@ const pageTitle = "Blog Posts";
4243
class={`${index !== 0 ? "border-t border-gray-100 dark:border-gray-700" : ""}`}
4344
>
4445
<BlogPostListItem
45-
url={`/posts/${post.slug}`}
46+
url={`/posts/${post.data.slug}`}
4647
title={post.data.title}
47-
datePublished={new Date(post.data.pubDate).toLocaleDateString(
48-
"en-US",
49-
{
50-
year: "numeric",
51-
month: "long",
52-
day: "numeric",
53-
},
54-
)}
48+
datePublished={new Date(
49+
post.data.datePublished,
50+
).toLocaleDateString("en-US", {
51+
year: "numeric",
52+
month: "long",
53+
day: "numeric",
54+
})}
5555
description={post.data.description}
5656
/>
5757
</div>

0 commit comments

Comments
 (0)