From ba4e31224d868b7f60afcaf416a9b1cb43b5f564 Mon Sep 17 00:00:00 2001 From: JR Date: Sat, 15 Jun 2024 08:29:04 +0200 Subject: [PATCH] Add head filter to config in virtualTemplate.js Add a head filter for rendering the nunjucks files --- src/virtualTemplate.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/virtualTemplate.js b/src/virtualTemplate.js index bda644a..a5246b5 100644 --- a/src/virtualTemplate.js +++ b/src/virtualTemplate.js @@ -142,18 +142,19 @@ async function eleventyFeedPlugin(eleventyConfig, options = {}) { }, layout: false, metadata: options.metadata, - // Get the first `n` elements of a collection. - head: function(array, n) { - if(!n || n === 0) { - return array; - } - if(n < 0) { - throw new Error("`collection.limit` option must be a positive number."); - } - return array.slice(0, n); - }, }; + // Get the first `n` elements of a collection. + eleventyConfig.addFilter('head', function(array, n) { + if(!n || n === 0) { + return array; + } + if(n < 0) { + throw new Error("`collection.limit` option must be a positive number."); + } + return array.slice(0, n); + }); + eleventyConfig.addTemplate(options.inputPath, getFeedContent(options), templateData); };