lewisdale.dev/config/filters/excerpt.js
Lewis Dale aab2e16d37
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 2m10s
Post about new bikes, manually set excerpt
2024-04-24 20:28:51 +01:00

13 lines
434 B
JavaScript

const createExcerpt = (post, limit ) => {
const withoutTags = post.content.replace(/(<([^>]+)>)/gi, "");
if (withoutTags.length > limit) {
return withoutTags.slice(0, limit) + " […]";
}
return withoutTags;
}
module.exports = function (eleventyConfig) {
eleventyConfig.addFilter('excerpt', (post, limit = 250) => {
return post.data.excerpt || createExcerpt(post, limit);
});
}