From d028418aa456d56962bc8515b649800581c4b57a Mon Sep 17 00:00:00 2001 From: Esteban Date: Wed, 22 Apr 2026 14:32:53 -0500 Subject: [PATCH] fix: clean markdown formatting in news excerpts --- src/components/cards/NewsList.astro | 14 ++++++++++++-- src/pages/[locale]/news/[id].astro | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/cards/NewsList.astro b/src/components/cards/NewsList.astro index 476b903..baad4f7 100644 --- a/src/components/cards/NewsList.astro +++ b/src/components/cards/NewsList.astro @@ -22,8 +22,18 @@ const location = locationArray.filter(Boolean).join(', '); const newsUrl = `/${locale}/news/${data.id}`; const rawContent = content?.body || ""; -const plainText = rawContent.replace(/^#.*$/gm, '').replace(/^###.*$/gm, '').trim(); -const words = plainText.split(/\s+/).slice(0, 40); +const plainText = rawContent + .replace(/^#.*$/gm, '') + .replace(/^###.*$/gm, '') + .replace(/\*\*([^*]+)\*\*/g, '$1') + .replace(/\*([^*]+)\*/g, '$1') + .replace(/_([^_]+)_/g, '$1') + .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + .replace(/^>.*$/gm, '') + .replace(/`[^`]+`/g, '') + .replace(/^[-*]\s+/gm, '') + .trim(); +const words = plainText.split(/\s+/).filter(w => w.length > 0).slice(0, 40); const excerpt = words.join(' ') + (words.length === 40 ? '...' : ''); --- diff --git a/src/pages/[locale]/news/[id].astro b/src/pages/[locale]/news/[id].astro index 363856c..04a8aeb 100644 --- a/src/pages/[locale]/news/[id].astro +++ b/src/pages/[locale]/news/[id].astro @@ -36,8 +36,18 @@ const routeTranslations = { const baseSlug = routeTranslations.news[locale] || routeTranslations.news.en; const rawContent = post.body || ""; -const plainText = rawContent.replace(/^#.*$/gm, '').replace(/^###.*$/gm, '').trim(); -const words = plainText.split(/\s+/).slice(0, 35); +const plainText = rawContent + .replace(/^#.*$/gm, '') + .replace(/^###.*$/gm, '') + .replace(/\*\*([^*]+)\*\*/g, '$1') + .replace(/\*([^*]+)\*/g, '$1') + .replace(/_([^_]+)_/g, '$1') + .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + .replace(/^>.*$/gm, '') + .replace(/`[^`]+`/g, '') + .replace(/^[-*]\s+/gm, '') + .trim(); +const words = plainText.split(/\s+/).filter(w => w.length > 0).slice(0, 35); const excerpt = words.join(' ') + (words.length === 35 ? '...' : ''); ---