Move random posts to most recently 3 posts

This commit is contained in:
Cassidy Williams
2022-11-16 23:10:11 -06:00
parent 6136cd2141
commit 795cdb2107
2 changed files with 12 additions and 3 deletions

View File

@@ -3,7 +3,16 @@ import Post from "../components/Post.astro";
const { allPosts } = Astro.props;
let posts = allPosts.sort(() => 0.5 - Math.random()).slice(0, 3);
// TODO: account for recently updated posts, too
let posts = allPosts
.sort(
(a, b) =>
new Date(b.frontmatter.added).valueOf() -
new Date(a.frontmatter.added).valueOf()
)
.slice(0, 3);
//.sort(() => 0.5 - Math.random()).slice(0, 3);
---
<content>