Add archives page

Blogs commonly only display the latest `n` blog posts on the home page, while showing the full list on a separate archive page. This change implements that.
master
Mathias Bynens 2018-09-19 16:52:49 +02:00
parent 4a517aecc1
commit 8b66ea9bea
3 changed files with 23 additions and 1 deletions

View File

@ -12,6 +12,11 @@ module.exports = function(eleventyConfig) {
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
});
// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
return array.slice(0, n);
});
// only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) {
return collection.getAllSorted().filter(function(item) {

12
archive.njk Normal file
View File

@ -0,0 +1,12 @@
---
layout: layouts/home.njk
tags:
- nav
navtitle: Archive
permalink: posts/index.html
---
<h1>Blog post archive</h1>
{% set postslist = collections.posts %}
{% include "postslist.njk" %}

View File

@ -4,5 +4,10 @@ tags:
- nav
navtitle: Home
---
{% set postslist = collections.posts %}
<h1>Latest 2 blog posts</h1>
{% set postslist = collections.posts | head(2) %}
{% include "postslist.njk" %}
<p>More posts can be found in <a href="/posts/">the blog archive</a>.</p>