From 293983eeb15c2554034f50ef5edd448c724a274b Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Tue, 9 Jul 2024 18:13:56 +0200 Subject: [PATCH] fix blog archive sorting --- src/pages/blog/index.astro | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 75f8d2d..bef5396 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -1,7 +1,23 @@ --- import { SEO } from "astro-seo"; import { format } from "date-fns"; + const posts = await Astro.glob("./posts/*.md"); + +posts.sort((a, b) => { + const dateA = new Date(a.frontmatter.pubDate); + const dateB = new Date(b.frontmatter.pubDate); + + if (dateA === dateB) { + return 0; + } + + if (dateA < dateB) { + return 1; + } + + return -1; +}); ---