feat: Series #31
|
@ -15,7 +15,8 @@ export function transformPostMeta(metadata: PostMetadata, slug: string) : Post {
|
|||
};
|
||||
}
|
||||
|
||||
export async function getPosts(tag: string | null = null) : Promise<Post[]> {
|
||||
// Generates a list of all posts filtering by tags and series
|
||||
export async function getPosts(filter: { tag?: string, series?: string }) : Promise<Post[]> {
|
||||
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<Post[]> {
|
|||
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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue