Refactored latest posts and with a correct sort. Uses dates on posts rather than file creation dates (unreliable).
This commit is contained in:
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;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user