Refactored latest posts and with a correct sort. Uses dates on posts rather than file creation dates (unreliable).
This commit is contained in:
parent
e2028fd551
commit
2402ba4887
10
.eleventy.js
10
.eleventy.js
@ -9,11 +9,15 @@ module.exports = function(eleventyConfig) {
|
||||
eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
|
||||
|
||||
eleventyConfig.addFilter("readableDate", dateObj => {
|
||||
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
|
||||
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy");
|
||||
});
|
||||
|
||||
// Get the first `n` elements of a collection.
|
||||
eleventyConfig.addFilter("head", (array, n) => {
|
||||
if( n < 0 ) {
|
||||
return array.slice(n);
|
||||
}
|
||||
|
||||
return array.slice(0, n);
|
||||
});
|
||||
|
||||
@ -24,8 +28,8 @@ module.exports = function(eleventyConfig) {
|
||||
|
||||
// only content in the `posts/` directory
|
||||
eleventyConfig.addCollection("posts", function(collection) {
|
||||
return collection.getAllSorted().filter(function(item) {
|
||||
return item.inputPath.startsWith('./posts');
|
||||
return collection.getFilteredByGlob("./posts/*").sort(function(a, b) {
|
||||
return a.date - b.date;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -3,10 +3,10 @@ layout: layouts/home.njk
|
||||
tags:
|
||||
- nav
|
||||
navtitle: Archive
|
||||
permalink: posts/index.html
|
||||
permalink: /posts/
|
||||
---
|
||||
|
||||
<h1>Blog post archive</h1>
|
||||
<h1>Archive</h1>
|
||||
|
||||
{% set postslist = collections.posts %}
|
||||
{% include "postslist.njk" %}
|
||||
|
@ -5,9 +5,9 @@ tags:
|
||||
navtitle: Home
|
||||
---
|
||||
|
||||
<h1>Latest 2 blog posts</h1>
|
||||
<h1>Latest 3 Posts</h1>
|
||||
|
||||
{% set postslist = collections.posts | head(2) %}
|
||||
{% set postslist = collections.posts | head(-3) %}
|
||||
{% include "postslist.njk" %}
|
||||
|
||||
<p>More posts can be found in <a href="/posts/">the blog archive</a>.</p>
|
||||
<p>More posts can be found in <a href="/posts/">the archive</a>.</p>
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
title: This is my first post.
|
||||
date: 2018-05-01
|
||||
tags:
|
||||
- post
|
||||
- another-tag
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
title: This is my fourth post.
|
||||
date: 2018-09-30
|
||||
tags: second-tag
|
||||
layout: layouts/post.njk
|
||||
---
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
title: This is my second post.
|
||||
date: 2018-07-04
|
||||
tags:
|
||||
- post
|
||||
- number-2
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
title: This is my third post.
|
||||
date: 2018-08-24
|
||||
tags:
|
||||
- post
|
||||
- second-tag
|
||||
|
Loading…
Reference in New Issue
Block a user