Add Archive page

This commit is contained in:
Shadowfacts 2020-08-21 22:37:57 -04:00
parent 04c43fa483
commit afb844db87
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 41 additions and 1 deletions

13
lib/generate/archive.ts Normal file
View File

@ -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);
}

View File

@ -1,3 +1,4 @@
import archive from "./archive";
import categories from "./categories"; import categories from "./categories";
import copy from "./copy"; import copy from "./copy";
import css from "./css"; import css from "./css";
@ -9,6 +10,7 @@ import tutorials from "./tutorials";
import years from "./years"; import years from "./years";
export = { export = {
archive,
categories, categories,
copy, copy,
css, css,

View File

@ -23,6 +23,7 @@ async function generate(): Promise<Page[]> {
generators.years(posts); generators.years(posts);
generators.rss.posts(posts) generators.rss.posts(posts)
generators.categories(posts).then(generators.rss.categories); generators.categories(posts).then(generators.rss.categories);
generators.archive(posts);
return posts; return posts;
} }

23
site/archive.html.ejs Normal file
View File

@ -0,0 +1,23 @@
```
metadata.layout = "default.html.ejs"
metadata.title = "Archive"
```
<div class="main">
<% let currentYear %>
<% for (const post of posts) { %>
<% if (post.metadata.date.getFullYear() !== currentYear) { %>
<% if (currentYear) { %>
</ul>
<% } %>
<% currentYear = post.metadata.date.getFullYear() %>
<h2><%= currentYear %></h2>
<ul>
<% } %>
<li>
<a href="<%= post.metadata.permalink %>">
<%= post.metadata.title %>
</a>
</li>
<% } %>
</div>

View File

@ -48,14 +48,15 @@
</div> </div>
<nav class="site-nav" role="navigation"> <nav class="site-nav" role="navigation">
<ul> <ul>
<li><%- fancyLink("Archive", "/archive/") %></li>
<li><%- fancyLink("Tutorials", "/tutorials/") %></li> <li><%- fancyLink("Tutorials", "/tutorials/") %></li>
<li><%- fancyLink("RTFM", "https://rtfm.shadowfacts.net") %></li> <li><%- fancyLink("RTFM", "https://rtfm.shadowfacts.net") %></li>
<li><%- fancyLink("Type", "https://type.shadowfacts.net") %></li>
<li> <li>
<a href="#" class="dropdown-link" aria-haspopup="true">Other <span class="arrow arrow-down" aria-hidden="true"></span></a> <a href="#" class="dropdown-link" aria-haspopup="true">Other <span class="arrow arrow-down" aria-hidden="true"></span></a>
<ul aria-label="other links"> <ul aria-label="other links">
<li><%- fancyLink("Gitea", "https://git.shadowfacts.net") %></li> <li><%- fancyLink("Gitea", "https://git.shadowfacts.net") %></li>
<li><%- fancyLink("Maven", "https://maven.shadowfacts.net") %></li> <li><%- fancyLink("Maven", "https://maven.shadowfacts.net") %></li>
<li><%- fancyLink("Type", "https://type.shadowfacts.net") %></li>
<li><%- fancyLink("Meme Machine", "https://mememachine.shadowfacts.net") %></li> <li><%- fancyLink("Meme Machine", "https://mememachine.shadowfacts.net") %></li>
</ul> </ul>
</li> </li>