fix: clean markdown formatting in news excerpts

This commit is contained in:
Esteban 2026-04-22 14:32:53 -05:00
parent 9c7f29bba1
commit d028418aa4
2 changed files with 24 additions and 4 deletions

View File

@ -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 ? '...' : '');
---

View File

@ -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 ? '...' : '');
---