22 lines
622 B
TypeScript
22 lines
622 B
TypeScript
|
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}`
|
||
|
});
|
||
|
});
|
||
|
}
|