Skip to content

Commit faa65f6

Browse files
committed
fix: sort posts by pubDate in descending order on home page
1 parent eed553b commit faa65f6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/pages/index.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import PostList from '@/components/PostList';
33
import BaseLayout from '@/layouts/BaseLayout.astro';
44
import { getCollection } from 'astro:content';
55
6-
const allPosts = await getCollection('posts');
6+
const allPosts = (await getCollection('posts')).sort(
7+
(a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime(),
8+
);
79
---
810

911
<BaseLayout pageTitle="Home">

0 commit comments

Comments
 (0)