Add year index pages
This commit is contained in:
parent
b796480112
commit
d39bfded01
|
@ -1,7 +1,7 @@
|
||||||
import { Page, PostMetadata } from "../metadata";
|
import { Page, PostMetadata } from "../metadata";
|
||||||
import generatePaginated from "./paginated";
|
import generatePaginated from "./paginated";
|
||||||
|
|
||||||
export default async function homepage(posts: Page[]): Promise<Map<string, Page[]>> {
|
export default async function(posts: Page[]): Promise<Map<string, Page[]>> {
|
||||||
const categories = new Map<string, Page[]>();
|
const categories = new Map<string, Page[]>();
|
||||||
|
|
||||||
for (const post of posts) {
|
for (const post of posts) {
|
||||||
|
@ -12,8 +12,8 @@ export default async function homepage(posts: Page[]): Promise<Map<string, Page[
|
||||||
categories.get(category)!.push(post);
|
categories.get(category)!.push(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
categories.forEach(async (categoryPosts, category) => {
|
categories.forEach((categoryPosts, category) => {
|
||||||
await generatePaginated(categoryPosts, `/${category}/`, "site/category.html.ejs", {
|
generatePaginated(categoryPosts, `/${category}/`, "site/category.html.ejs", {
|
||||||
category
|
category
|
||||||
}, {
|
}, {
|
||||||
title: `${category} posts`
|
title: `${category} posts`
|
||||||
|
|
|
@ -6,6 +6,7 @@ import homepage from "./homepage";
|
||||||
import posts from "./posts";
|
import posts from "./posts";
|
||||||
import rss from "./rss";
|
import rss from "./rss";
|
||||||
import tutorials from "./tutorials";
|
import tutorials from "./tutorials";
|
||||||
|
import years from "./years";
|
||||||
|
|
||||||
export = {
|
export = {
|
||||||
categories,
|
categories,
|
||||||
|
@ -15,5 +16,6 @@ export = {
|
||||||
homepage,
|
homepage,
|
||||||
posts,
|
posts,
|
||||||
rss,
|
rss,
|
||||||
tutorials
|
tutorials,
|
||||||
|
years,
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as metadata from "../metadata";
|
||||||
import { Page, PostMetadata } from "../metadata";
|
import { Page, PostMetadata } from "../metadata";
|
||||||
import layout from "../layout";
|
import layout from "../layout";
|
||||||
|
|
||||||
export default async function generatePaginted(posts: Page[], basePath: string, templatePath: string, extraData?: object, extraMetadata?: object) {
|
export default async function generatePaginated(posts: Page[], basePath: string, templatePath: string, extraData?: object, extraMetadata?: object) {
|
||||||
const page = await metadata.get(templatePath);
|
const page = await metadata.get(templatePath);
|
||||||
|
|
||||||
if (extraMetadata) page.metadata = {...page.metadata, ...extraMetadata};
|
if (extraMetadata) page.metadata = {...page.metadata, ...extraMetadata};
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
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}`
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ async function generate(): Promise<Page[]> {
|
||||||
|
|
||||||
const posts = await generators.posts();
|
const posts = await generators.posts();
|
||||||
generators.homepage(posts);
|
generators.homepage(posts);
|
||||||
|
generators.years(posts);
|
||||||
const categories = await generators.categories(posts);
|
const categories = await generators.categories(posts);
|
||||||
await generators.rss(posts, categories, tutorials);
|
await generators.rss(posts, categories, tutorials);
|
||||||
|
|
||||||
|
|
|
@ -9,43 +9,8 @@ metadata.layout = "default.html.ejs"
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<% for (const post of posts) { %>
|
<% for (const post of posts) { %>
|
||||||
<article itemscope itemtype="https://schema.org/BlogPosting">
|
<%- include("includes/article-listing.html.ejs", { post }) %>
|
||||||
<h2 class="article-title" itemprop="headline">
|
|
||||||
<a href="<%= post.metadata.permalink %>" itemprop="url mainEntityOfPage">
|
|
||||||
<%= post.metadata.title %>
|
|
||||||
</a>
|
|
||||||
</h2>
|
|
||||||
<%- include("includes/article-meta.html.ejs", { metadata: post.metadata }) %>
|
|
||||||
<div class="article-content" itemprop="description">
|
|
||||||
<%- post.metadata.excerpt %>
|
|
||||||
</div>
|
|
||||||
<p class="read-more-link">
|
|
||||||
<a href="<%= post.metadata.permalink %>">Read more...</a>
|
|
||||||
</p>
|
|
||||||
</article>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pagination">
|
<%- include("includes/pagination.html.ejs", { pagination }) %>
|
||||||
<p>
|
|
||||||
<span class="pagination-link">
|
|
||||||
<% if (pagination.prevLink) { %>
|
|
||||||
<a href="<%= pagination.prevLink %>">
|
|
||||||
<span class="arrow-left"></span> Previous
|
|
||||||
</a>
|
|
||||||
<% } else { %>
|
|
||||||
<span class="arrow-left"></span> Previous
|
|
||||||
<% } %>
|
|
||||||
</span>
|
|
||||||
Page <%= pagination.current %> of <%= pagination.total %>
|
|
||||||
<span class="pagination-link">
|
|
||||||
<% if (pagination.nextLink) { %>
|
|
||||||
<a href="<%= pagination.nextLink %>">
|
|
||||||
Next <span class="arrow-right"></span>
|
|
||||||
</a>
|
|
||||||
<% } else { %>
|
|
||||||
Next <span class="arrow-right"></span>
|
|
||||||
<% } %>
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<article itemscope itemtype="https://schema.org/BlogPosting">
|
||||||
|
<h2 class="article-title" itemprop="headline">
|
||||||
|
<a href="<%= post.metadata.permalink %>" itemprop="url mainEntityOfPage">
|
||||||
|
<%= post.metadata.title %>
|
||||||
|
</a>
|
||||||
|
</h2>
|
||||||
|
<%- include("article-meta.html.ejs", { metadata: post.metadata }) %>
|
||||||
|
<div class="article-content" itemprop="description">
|
||||||
|
<%- post.metadata.excerpt %>
|
||||||
|
</div>
|
||||||
|
<p class="read-more-link">
|
||||||
|
<a href="<%= post.metadata.permalink%>">Read more...</a>
|
||||||
|
</p>
|
||||||
|
</article>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<div class="pagination" role="navigation">
|
||||||
|
<p>
|
||||||
|
<span class="pagination-link">
|
||||||
|
<% if (pagination.prevLink) { %>
|
||||||
|
<a href="<%= pagination.prevLink %>">
|
||||||
|
<span class="arrow arrow-left" aria-hidden="true"></span> <span>Previous</span>
|
||||||
|
</a>
|
||||||
|
<% } else { %>
|
||||||
|
<span class="arrow arrow-left" aria-hidden="true"></span> <span>Previous</span>
|
||||||
|
<% } %>
|
||||||
|
</span>
|
||||||
|
Page <%= pagination.current %> of <%= pagination.total %>
|
||||||
|
<span class="pagination-link">
|
||||||
|
<% if (pagination.nextLink) { %>
|
||||||
|
<a href="<%= pagination.nextLink %>">
|
||||||
|
<span>Next</span> <span class="arrow arrow-right" aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
<% } else { %>
|
||||||
|
<span>Next</span> <span class="arrow arrow-right" aria-hidden="true"></span>
|
||||||
|
<% } %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
|
@ -5,43 +5,8 @@ metadata.layout = "default.html.ejs"
|
||||||
|
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<% for (const post of posts) { %>
|
<% for (const post of posts) { %>
|
||||||
<article itemscope itemtype="https://schema.org/BlogPosting">
|
<%- include("includes/article-listing.html.ejs", { post }) %>
|
||||||
<h1 class="article-title" itemprop="headline">
|
|
||||||
<a href="<%= post.metadata.permalink %>" itemprop="url mainEntityOfPage">
|
|
||||||
<%= post.metadata.title %>
|
|
||||||
</a>
|
|
||||||
</h1>
|
|
||||||
<%- include("includes/article-meta.html.ejs", { metadata: post.metadata }) %>
|
|
||||||
<div class="article-content" itemprop="description">
|
|
||||||
<%- post.metadata.excerpt %>
|
|
||||||
</div>
|
|
||||||
<p class="read-more-link">
|
|
||||||
<a href="<%= post.metadata.permalink %>">Read more...</a>
|
|
||||||
</p>
|
|
||||||
</article>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pagination" role="navigation">
|
<%- include("includes/pagination.html.ejs", { pagination }) %>
|
||||||
<p>
|
|
||||||
<span class="pagination-link">
|
|
||||||
<% if (pagination.prevLink) { %>
|
|
||||||
<a href="<%= pagination.prevLink %>">
|
|
||||||
<span class="arrow arrow-left" aria-hidden="true"></span> <span>Previous</span>
|
|
||||||
</a>
|
|
||||||
<% } else { %>
|
|
||||||
<span class="arrow arrow-left" aria-hidden="true"></span> <span>Previous</span>
|
|
||||||
<% } %>
|
|
||||||
</span>
|
|
||||||
Page <%= pagination.current %> of <%= pagination.total %>
|
|
||||||
<span class="pagination-link">
|
|
||||||
<% if (pagination.nextLink) { %>
|
|
||||||
<a href="<%= pagination.nextLink %>">
|
|
||||||
<span>Next</span> <span class="arrow arrow-right" aria-hidden="true"></span>
|
|
||||||
</a>
|
|
||||||
<% } else { %>
|
|
||||||
<span>Next</span> <span class="arrow arrow-right" aria-hidden="true"></span>
|
|
||||||
<% } %>
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
```
|
||||||
|
metadata.layout = "default.html.ejs"
|
||||||
|
```
|
||||||
|
|
||||||
|
<div class="main">
|
||||||
|
<h1 class="page-heading">Posts from <%= year %></h1>
|
||||||
|
|
||||||
|
<% for (const post of posts) { %>
|
||||||
|
<%- include("includes/article-listing.html.ejs", { post }) %>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%- include("includes/pagination.html.ejs", { pagination }) %>
|
Loading…
Reference in New Issue