From cfb71d3f32b9cac9bc1b4cd5c2cbf892d81622ab Mon Sep 17 00:00:00 2001 From: TrebledJ <39648915+TrebledJ@users.noreply.github.com> Date: Thu, 9 Nov 2023 00:09:49 +0800 Subject: [PATCH] fix: prev --- content/redirect-from.njk | 2 +- eleventy/filters.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/content/redirect-from.njk b/content/redirect-from.njk index 231101fee..c5075f003 100644 --- a/content/redirect-from.njk +++ b/content/redirect-from.njk @@ -45,7 +45,7 @@ {% endif %} {% if redirect.page.data.excerpt %} - {% set meta_desc = (redirect.page.data.excerpt | mdInline | striptags) + "\n\n" + (redirect.page.data.content | annihilate('.article-header, .metadata-container, .metadata-tag-container, #toc-sidebar') | striptags | truncateWords(30)) %} + {% set meta_desc = (redirect.page.data.excerpt | mdInline | striptags) + "\n\n" + (redirect.page.content | annihilate('.article-header, .metadata-container, .metadata-tag-container, #toc-sidebar') | striptags | truncateWords(30)) %} {% else %} {% set meta_desc = site.description %} {% endif %} diff --git a/eleventy/filters.js b/eleventy/filters.js index 54bf13641..cf15972f7 100644 --- a/eleventy/filters.js +++ b/eleventy/filters.js @@ -86,6 +86,9 @@ module.exports = function (eleventyConfig) { return tags.reduce((acc, x) => acc.replace(dumbHTMLRegex(x), ''), html); }); eleventyConfig.addFilter('annihilate', (html, selector) => { + if (typeof html !== 'string') { + throw new Error(`[11ty] annihilate: expected HTML string, got ${typeof html}`); + } const $ = cheerio.load(html); $(selector).remove(); return $.html();