Skip to content

Commit cb47ae2

Browse files
committed
auto-blurb
1 parent 82b3036 commit cb47ae2

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

.eleventy.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ module.exports = function(eleventyConfig) {
9090
return `${months[d.getUTCMonth()]} ${d.getUTCDate()}, ${d.getUTCFullYear()}`;
9191
});
9292

93+
/* Auto-blurb filter: strips HTML and truncates content */
94+
eleventyConfig.addFilter("autoBlurb", (content, maxLength = 150) => {
95+
if (!content) return "";
96+
// Strip HTML tags
97+
const text = content.replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim();
98+
if (text.length <= maxLength) return text;
99+
// Truncate at word boundary
100+
const truncated = text.substring(0, maxLength);
101+
const lastSpace = truncated.lastIndexOf(" ");
102+
return (lastSpace > 0 ? truncated.substring(0, lastSpace) : truncated) + "...";
103+
});
104+
93105
/* Set directories */
94106
return {
95107
dir: {

0 commit comments

Comments
 (0)