lewisdale.dev/config/filters/excerpt.js

15 lines
510 B
JavaScript
Raw Normal View History

const createExcerpt = (post, limit ) => {
2024-04-29 18:15:13 +00:00
const withoutTags = post.content.replace(/(<([^>]+)>)/gi, "")
.replace(/[^\x20-\x7E]/gmi, " ")
.replace(/\s+/g, " ").trim();
if (withoutTags.length > limit) {
return withoutTags.slice(0, limit) + " […]";
}
return withoutTags;
}
2024-10-06 11:36:54 +00:00
export default function (eleventyConfig) {
eleventyConfig.addFilter('excerpt', (post, limit = 250) => {
return post.data.excerpt || createExcerpt(post, limit);
});
}