Move random posts to most recently 3 posts
This commit is contained in:
29
src/components/HomePosts.astro
Normal file
29
src/components/HomePosts.astro
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
import Post from "../components/Post.astro";
|
||||
|
||||
const { allPosts } = Astro.props;
|
||||
|
||||
// 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>
|
||||
<ul>
|
||||
{
|
||||
posts.map(
|
||||
({
|
||||
url,
|
||||
frontmatter: { description, slug, title, tags, added: date },
|
||||
}) => <Post {url} {description} {date} {slug} {title} {tags} />
|
||||
)
|
||||
}
|
||||
</ul>
|
||||
</content>
|
||||
Reference in New Issue
Block a user