feat: allow showing featured posts

This commit is contained in:
Stefan Imhoff
2023-06-10 16:46:09 +02:00
parent 7acad66be9
commit 903d0549d7

View File

@@ -7,19 +7,21 @@ export const formatPosts = (
{
removeDrafts = true,
removeFuture = true,
showFeatured,
sortBy = 'date',
sortOrder = 'desc',
limit,
}: {
removeDrafts?: boolean;
removeFuture?: boolean;
showFeatured?: boolean;
sortBy?: 'date' | 'alphabet' | 'random';
sortOrder?: 'asc' | 'desc';
limit?: number;
}
): CollectionEntry<'journal'>[] => {
const filteredPosts = posts.reduce((acc: CollectionEntry<'journal'>[], post) => {
const { date, draft } = post.data;
const { date, draft, featured } = post.data;
// Remove draft content
if (removeDrafts && draft) return acc;
@@ -27,6 +29,9 @@ export const formatPosts = (
// Remove future content
if (removeFuture && new Date(date) > new Date()) return acc;
// Show featured only
if (showFeatured && !featured) return acc;
acc.push(post);
return acc;