forked from shadowfacts/shadowfacts.net
24 lines
638 B
TypeScript
24 lines
638 B
TypeScript
import { Page, PostMetadata } from "../metadata";
|
|
import generatePaginated from "./paginated";
|
|
|
|
export default async function(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((categoryPosts, category) => {
|
|
generatePaginated(categoryPosts, `/${category}/`, "site/category.html.ejs", {
|
|
category
|
|
}, {
|
|
title: `${category} posts`
|
|
});
|
|
});
|
|
|
|
return categories;
|
|
} |