From afb844db8718fd5dfe9d0e5ae030e903d1f07f68 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 21 Aug 2020 22:37:57 -0400 Subject: [PATCH] Add Archive page --- lib/generate/archive.ts | 13 +++++++++++++ lib/generate/index.ts | 2 ++ lib/index.ts | 1 + site/archive.html.ejs | 23 +++++++++++++++++++++++ site/layouts/default.html.ejs | 3 ++- 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/generate/archive.ts create mode 100644 site/archive.html.ejs diff --git a/lib/generate/archive.ts b/lib/generate/archive.ts new file mode 100644 index 0000000..38744c1 --- /dev/null +++ b/lib/generate/archive.ts @@ -0,0 +1,13 @@ +import * as metadata from "../metadata"; +import { Page } from "../metadata"; +import * as util from "../util"; +import layout from "../layout"; + +export default async function archive(posts: Page[]) { + const page = await metadata.get("site/archive.html.ejs"); + page.text = util.render(page.text, { + posts, + }, "site/archive.html.ejs"); + page.text = await layout(page.text, page.metadata, page.metadata.layout!); + util.write("archive/index.html", page.text); +} diff --git a/lib/generate/index.ts b/lib/generate/index.ts index d0efb81..20b1ca5 100644 --- a/lib/generate/index.ts +++ b/lib/generate/index.ts @@ -1,3 +1,4 @@ +import archive from "./archive"; import categories from "./categories"; import copy from "./copy"; import css from "./css"; @@ -9,6 +10,7 @@ import tutorials from "./tutorials"; import years from "./years"; export = { + archive, categories, copy, css, diff --git a/lib/index.ts b/lib/index.ts index 92601f8..614cae7 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -23,6 +23,7 @@ async function generate(): Promise { generators.years(posts); generators.rss.posts(posts) generators.categories(posts).then(generators.rss.categories); + generators.archive(posts); return posts; } diff --git a/site/archive.html.ejs b/site/archive.html.ejs new file mode 100644 index 0000000..d5a6605 --- /dev/null +++ b/site/archive.html.ejs @@ -0,0 +1,23 @@ +``` +metadata.layout = "default.html.ejs" +metadata.title = "Archive" +``` + +
+ <% let currentYear %> + <% for (const post of posts) { %> + <% if (post.metadata.date.getFullYear() !== currentYear) { %> + <% if (currentYear) { %> + + <% } %> + <% currentYear = post.metadata.date.getFullYear() %> +

<%= currentYear %>

+
diff --git a/site/layouts/default.html.ejs b/site/layouts/default.html.ejs index fdfe8ff..da1e3ab 100644 --- a/site/layouts/default.html.ejs +++ b/site/layouts/default.html.ejs @@ -48,14 +48,15 @@