From 7d1fe776c78c2e43586a2411e2ef5d7957ac13ca Mon Sep 17 00:00:00 2001 From: Lee Cattarin Date: Fri, 20 Feb 2026 08:36:46 -0800 Subject: [PATCH] add related posts and update some styling --- _config/filters.js | 41 ++++++++++++++++++- _includes/layouts/base.njk | 2 - _includes/layouts/post.njk | 13 ++++++ css/main.css | 15 +++---- css/nav.css | 4 +- css/post.css | 1 - src/posts/2026/2026-02-19-eleventy-lessons.md | 16 +++++--- 7 files changed, 73 insertions(+), 19 deletions(-) diff --git a/_config/filters.js b/_config/filters.js index 03042e8..4a8f348 100644 --- a/_config/filters.js +++ b/_config/filters.js @@ -6,11 +6,50 @@ export default function(eleventyConfig) { return Object.keys(target); }); + /* Exclude all posts with given URLs from a collection list */ + eleventyConfig.addFilter("excludeFromCollection", function (collection=[], urls=[this.ctx.page.url]) { + return collection.filter(post => urls.indexOf(post.url) === -1); + }); + + /* Filter a collection by a set of tags, returning any that share one or more tags */ + eleventyConfig.addFilter("filterByTags", function(collection=[], ...requiredTags) { + return collection.filter(post => { + return requiredTags.flat().some(tag => post.data.tags.includes(tag)); + }); + }); + + /* Return n elements from a list */ + eleventyConfig.addFilter("head", (collection=[], n) => { + if(!Array.isArray(collection) || collection.length === 0) { + return []; + } + if( n < 0 ) { + return collection.slice(n); + } + + return collection.slice(0, n); + }); + + /* For