From e7f41976f1d0c0467eaf293e3524773fd4ee4eef Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Mon, 15 Jul 2024 16:14:41 +0100 Subject: Feeds use max entries, and blog feed uses descriptions --- website/src/components/BlogFeed.astro | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'website/src/components/BlogFeed.astro') diff --git a/website/src/components/BlogFeed.astro b/website/src/components/BlogFeed.astro index 525d7ba..3d6352d 100644 --- a/website/src/components/BlogFeed.astro +++ b/website/src/components/BlogFeed.astro @@ -1,15 +1,21 @@ --- import type { CollectionEntry } from 'astro:content'; import { getCollection } from 'astro:content'; +import FormattedDate from './FormattedDate.astro'; export interface Props { headingLevel?: 1 | 2 | 3 | 4 | 5 | 6, hideAuthor?: boolean, + maxEntries?: number, }; -const { headingLevel = 2, hideAuthor = false } = Astro.props; +const { headingLevel = 2, hideAuthor = false, maxEntries } = Astro.props; -const posts = (await getCollection('blog')).filter((post) => !post.data.hidden); +const allPosts = (await getCollection('blog')).filter((post) => !post.data.hidden); + +const posts = maxEntries === undefined + ? allPosts + : allPosts.sort(sortByPubDateDescending).slice(0, maxEntries); const distinctYears: number[] = posts .map(post => post.data.pubDate.getFullYear()) @@ -58,9 +64,16 @@ const canonicalBlogUrl = new URL('blog', Astro.site) )) } + + { (maxEntries !== undefined && maxEntries < allPosts.length) + ? + : <> + } -- cgit v1.2.3