shadowfacts.net/lib/generate/categories.ts

24 lines
659 B
TypeScript
Raw Normal View History

2019-01-04 18:14:53 +00:00
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;
}