only show 3 posts on the homepage

This commit is contained in:
LWinterberg
2023-11-01 16:09:52 +01:00
parent fd532308f3
commit 3f2cbdb793

View File

@@ -5,6 +5,8 @@ import { getCollection } from "astro:content";
const publishedBlogPosts = await getCollection("blog", ({ data }) => {
return data.draft !== true;
});
const maxposts = 3;
---
<section class="pt-8 pb-16">
@@ -15,7 +17,10 @@ const publishedBlogPosts = await getCollection("blog", ({ data }) => {
<div class="grid grid-cols-12 my-4 sm:my-8 md:my-12 gap-y-8 sm:gap-8 md:gap-12">
{
publishedBlogPosts.sort((a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime()).map((post) => {
publishedBlogPosts
.sort((a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime())
.slice(0,maxposts)
.map((post) => {
return (
<NEWBlogPostCard
href={post.slug}