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