Refactored latest posts and with a correct sort. Uses dates on posts rather than file creation dates (unreliable).

This commit is contained in:
Zach Leatherman
2018-09-30 00:09:09 -05:00
parent e2028fd551
commit 2402ba4887
7 changed files with 16 additions and 8 deletions

View File

@@ -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;
});
});