2019-01-04 18:14:53 +00:00
|
|
|
import { Page, PostMetadata } from "../metadata";
|
|
|
|
import generatePaginated from "./paginated";
|
|
|
|
|
2020-01-28 00:31:59 +00:00
|
|
|
export default async function(posts: Page[]): Promise<Map<string, Page[]>> {
|
2019-01-04 18:14:53 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-01-28 00:31:59 +00:00
|
|
|
categories.forEach((categoryPosts, category) => {
|
|
|
|
generatePaginated(categoryPosts, `/${category}/`, "site/category.html.ejs", {
|
2019-01-04 18:14:53 +00:00
|
|
|
category
|
|
|
|
}, {
|
|
|
|
title: `${category} posts`
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return categories;
|
|
|
|
}
|