shadowfacts.net/lib/generate/years.ts

22 lines
622 B
TypeScript
Raw Permalink Normal View History

2020-01-28 00:31:59 +00:00
import {Page, PostMetadata} from "../metadata";
import generatePaginated from "./paginated";
export default async function(posts: Page[]) {
const years = new Map<number, Page[]>();
for (const post of posts) {
const year = (<Date>(<PostMetadata>post.metadata).date).getFullYear();
if (!years.has(year)) {
years.set(year, []);
}
years.get(year)!.push(post)
}
years.forEach((yearPosts, year) => {
generatePaginated(yearPosts, `/${year}/`, "site/year.html.ejs", {
year
}, {
title: `Posts from ${year}`
});
});
}