2024-04-24 19:28:51 +00:00
|
|
|
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();
|
2024-03-14 07:34:33 +00:00
|
|
|
|
|
|
|
if (withoutTags.length > limit) {
|
|
|
|
return withoutTags.slice(0, limit) + " […]";
|
|
|
|
}
|
|
|
|
return withoutTags;
|
2024-04-24 19:28:51 +00:00
|
|
|
}
|
2024-10-06 11:36:54 +00:00
|
|
|
export default function (eleventyConfig) {
|
2024-04-24 19:28:51 +00:00
|
|
|
eleventyConfig.addFilter('excerpt', (post, limit = 250) => {
|
|
|
|
return post.data.excerpt || createExcerpt(post, limit);
|
2023-12-26 14:35:09 +00:00
|
|
|
});
|
|
|
|
}
|