From 6365a30bfe3f6f279b87b26fe0c0c8f71ce1f919 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20P=C4=99dzich?=
Date: Mon, 22 May 2023 21:32:01 +0200
Subject: [PATCH] Add a limit prop to PostList component
---
src/components/PostList.astro | 10 +++++++---
src/pages/blog/index.astro | 2 +-
src/pages/index.astro | 17 +++--------------
3 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/src/components/PostList.astro b/src/components/PostList.astro
index 0c0f979..eaaced6 100644
--- a/src/components/PostList.astro
+++ b/src/components/PostList.astro
@@ -3,17 +3,21 @@ import { CollectionEntry, getCollection } from 'astro:content';
export interface Props {
filterFn?: (entry: CollectionEntry<'blog'>) => unknown;
+ limit?: number;
}
-const defaultFilterFn = (entry: CollectionEntry<'blog'>) => true;
-const { filterFn = defaultFilterFn } = Astro.props;
+const defaultFilterFn = (_entry: CollectionEntry<'blog'>) => true;
+
+const { filterFn = defaultFilterFn, limit } = Astro.props;
const posts = (
await getCollection(
'blog',
(entry) => filterFn(entry) && (import.meta.env.DEV || !entry.data.draft)
)
-).sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
+)
+ .sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
+ .slice(0, limit);
---
{
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro
index bea0945..637bff1 100644
--- a/src/pages/blog/index.astro
+++ b/src/pages/blog/index.astro
@@ -7,5 +7,5 @@ import PostList from '../../components/PostList.astro';
title="blog"
description="blog about the making of maciej's projects and more"
>
-
+
diff --git a/src/pages/index.astro b/src/pages/index.astro
index 9e09778..f0f09e8 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -1,4 +1,5 @@
---
+import PostList from '../components/PostList.astro';
import { SITE_DESCRIPTION } from '../consts';
import BaseLayout from '../layouts/BaseLayout.astro';
---
@@ -23,22 +24,10 @@ import BaseLayout from '../layouts/BaseLayout.astro';
workings of my applications. Check out the latest
posts below:
-
+
- Enjoy my work?
+ Like my work?
If so, make sure to follow me on