Skip to content

Commit 4e14c77

Browse files
fix(site): display blog posts in reverse chronological order (#100)
1 parent 89e27e7 commit 4e14c77

File tree

2 files changed

+28
-108
lines changed

2 files changed

+28
-108
lines changed
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
2-
import { getCollection } from 'astro:content';
3-
import ArticleCard from '~/components/ArticleCard.astro';
4-
import Layout from '~/layouts/Layout.astro';
2+
import { getCollection } from "astro:content";
3+
import ArticleCard from "~/components/ArticleCard.astro";
4+
import Layout from "~/layouts/Layout.astro";
55
6-
const title = 'Articles';
7-
const articles = await getCollection('blog', ({ data }) => {
8-
return import.meta.env.PROD ? data.draft !== true : true;
6+
const title = "Articles";
7+
const sortedArticles = (
8+
await getCollection("blog", ({ data }) => {
9+
return import.meta.env.PROD ? data.draft !== true : true;
10+
})
11+
).sort((a, b) => {
12+
return b.data.publishDate.getTime() - a.data.publishDate.getTime();
913
});
1014
---
1115

@@ -16,8 +20,8 @@ const articles = await getCollection('blog', ({ data }) => {
1620
>
1721
{title}
1822
</h1>
19-
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2 mt-8">
20-
{articles.map((article) => <ArticleCard {article} />)}
23+
<div class="grid grid-cols-1 gap-4 mt-8">
24+
{sortedArticles.map((article) => <ArticleCard {article} />)}
2125
</div>
2226
</div>
2327
</Layout>

pnpm-lock.yaml

Lines changed: 16 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)