diff --git a/src/lib/posts.ts b/src/lib/posts.ts index d0fe91f..9984e6d 100644 --- a/src/lib/posts.ts +++ b/src/lib/posts.ts @@ -15,7 +15,8 @@ export function transformPostMeta(metadata: PostMetadata, slug: string) : Post { }; } -export async function getPosts(tag: string | null = null) : Promise { +// Generates a list of all posts filtering by tags and series +export async function getPosts(filter: { tag?: string, series?: string }) : Promise { const allPostFiles = import.meta.glob('$content/post/*.md'); const iterablePostFiles = Object.entries(allPostFiles); @@ -27,8 +28,10 @@ export async function getPosts(tag: string | null = null) : Promise { return transformPostMeta(metadata, slug); }) ); - if (tag) - posts = posts.filter(post => post.tags.includes(tag)) + if (filter?.tag) + posts = posts.filter(post => post.tags.includes(filter.tag!)) + if (filter?.series) + posts = posts.filter(post => post.series?.includes(filter.series!) ?? false) posts.sort((post1, post2) => { const date1: Date = post1.date; diff --git a/src/routes/tag/[slug]/+page.ts b/src/routes/tag/[slug]/+page.ts index f3a0fe0..6d2fafd 100644 --- a/src/routes/tag/[slug]/+page.ts +++ b/src/routes/tag/[slug]/+page.ts @@ -2,7 +2,7 @@ import type { PageLoad } from './$types'; import { getPosts } from '$lib/posts'; export const load: PageLoad = async ({ params }) => { - const posts = await getPosts(params.slug); + const posts = await getPosts({ tag: params.slug }); return { name: params.slug, posts,