feat: Series #31

Open
aniva wants to merge 1 commits from post/series into main
2 changed files with 7 additions and 4 deletions
Showing only changes of commit d18c3f62c7 - Show all commits

View File

@ -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;

View File

@ -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,