Skip to content

Commit

Permalink
Merge pull request #51 from jeanremy/patch-1
Browse files Browse the repository at this point in the history
Add head filter to config in virtualTemplate.js
  • Loading branch information
zachleat committed Jun 17, 2024
2 parents e1c9a3d + ba4e312 commit c9f12d2
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 c9f12d2

Please sign in to comment.