diff --git a/.eleventy.js b/.eleventy.js index b387b3c..48a2aab 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -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) { diff --git a/archive.njk b/archive.njk new file mode 100644 index 0000000..235fd75 --- /dev/null +++ b/archive.njk @@ -0,0 +1,12 @@ +--- +layout: layouts/home.njk +tags: + - nav +navtitle: Archive +permalink: posts/index.html +--- + +

Blog post archive

+ +{% set postslist = collections.posts %} +{% include "postslist.njk" %} diff --git a/index.njk b/index.njk index 9a30ce5..db6baea 100644 --- a/index.njk +++ b/index.njk @@ -4,5 +4,10 @@ tags: - nav navtitle: Home --- -{% set postslist = collections.posts %} + +

Latest 2 blog posts

+ +{% set postslist = collections.posts | head(2) %} {% include "postslist.njk" %} + +

More posts can be found in the blog archive.