Merge pull request #20 from mathiasbynens/last-x-posts
Add archives page
This commit is contained in:
commit
32ea990f46
@ -12,6 +12,11 @@ module.exports = function(eleventyConfig) {
|
|||||||
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
|
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
|
||||||
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
|
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
|
||||||
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd');
|
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd');
|
||||||
|
12
archive.njk
Normal file
12
archive.njk
Normal 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" %}
|
@ -4,5 +4,10 @@ tags:
|
|||||||
- nav
|
- nav
|
||||||
navtitle: Home
|
navtitle: Home
|
||||||
---
|
---
|
||||||
{% set postslist = collections.posts %}
|
|
||||||
|
<h1>Latest 2 blog posts</h1>
|
||||||
|
|
||||||
|
{% set postslist = collections.posts | head(2) %}
|
||||||
{% include "postslist.njk" %}
|
{% include "postslist.njk" %}
|
||||||
|
|
||||||
|
<p>More posts can be found in <a href="/posts/">the blog archive</a>.</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user