Skip to content

Commit

Permalink
Add head filter to config in virtualTemplate.js
Browse files Browse the repository at this point in the history
Add a head filter for rendering the nunjucks files
  • Loading branch information
jeanremy authored Jun 15, 2024
1 parent e1c9a3d commit ba4e312
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/virtualTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit ba4e312

Please sign in to comment.