forked from shadowfacts/shadowfacts.net
24 lines
659 B
TypeScript
24 lines
659 B
TypeScript
|
import { Page, PostMetadata } from "../metadata";
|
||
|
import generatePaginated from "./paginated";
|
||
|
|
||
|
export default async function homepage(posts: Page[]): Promise<Map<string, Page[]>> {
|
||
|
const categories = new Map<string, Page[]>();
|
||
|
|
||
|
for (const post of posts) {
|
||
|
const category = (<PostMetadata>post.metadata).category;
|
||
|
if (!categories.has(category)) {
|
||
|
categories.set(category, []);
|
||
|
}
|
||
|
categories.get(category)!.push(post);
|
||
|
}
|
||
|
|
||
|
categories.forEach(async (categoryPosts, category) => {
|
||
|
await generatePaginated(categoryPosts, `/${category}/`, "site/category.html.ejs", {
|
||
|
category
|
||
|
}, {
|
||
|
title: `${category} posts`
|
||
|
});
|
||
|
});
|
||
|
|
||
|
return categories;
|
||
|
}
|