From 14392538c71e347b68dbeb43017a55913762a39a Mon Sep 17 00:00:00 2001 From: John Costa Date: Sat, 3 Sep 2022 12:01:29 +0100 Subject: [PATCH] added dates to posts --- src/pages/blog.astro | 7 ++++++- src/pages/posts/Threaded-js.md | 1 + src/pages/posts/deepwork-review.md | 1 + src/pages/posts/therepublic-review.md | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pages/blog.astro b/src/pages/blog.astro index 6c46e0e..4b94846 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -2,6 +2,11 @@ import Navbar from '../components/Navbar.astro' const posts = await Astro.glob('./posts/*.md'); +const sortedPosts = posts.sort((a, b) => { + const splitA = a.frontmatter.date.split("/"); + const splitB = b.frontmatter.date.split("/"); + return new Date(splitB[1], splitB[0], splitB[2]).getTime() - new Date(splitA[1], splitA[0], splitA[2]).getTime() +}); --- @@ -10,7 +15,7 @@ const posts = await Astro.glob('./posts/*.md');