Skip to content

Commit b9ef735

Browse files
authored
fix: sort archive posts by pubDatetime (#415)
1 parent 63fe796 commit b9ef735

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/pages/archives/index.astro

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ const MonthMap: Record<string, string> = {
5959
<sup class="text-xs">{monthGroup.length}</sup>
6060
</div>
6161
<ul>
62-
{monthGroup.map(({ data, slug }) => (
63-
<Card href={`/posts/${slug}`} frontmatter={data} />
64-
))}
62+
{monthGroup
63+
.sort(
64+
(a, b) =>
65+
Math.floor(
66+
new Date(b.data.pubDatetime).getTime() / 1000
67+
) -
68+
Math.floor(
69+
new Date(a.data.pubDatetime).getTime() / 1000
70+
)
71+
)
72+
.map(({ data, slug }) => (
73+
<Card href={`/posts/${slug}`} frontmatter={data} />
74+
))}
6575
</ul>
6676
</div>
6777
))}

0 commit comments

Comments
 (0)