fix: clean markdown formatting in news excerpts
This commit is contained in:
parent
9c7f29bba1
commit
d028418aa4
|
|
@ -22,8 +22,18 @@ const location = locationArray.filter(Boolean).join(', ');
|
||||||
const newsUrl = `/${locale}/news/${data.id}`;
|
const newsUrl = `/${locale}/news/${data.id}`;
|
||||||
|
|
||||||
const rawContent = content?.body || "";
|
const rawContent = content?.body || "";
|
||||||
const plainText = rawContent.replace(/^#.*$/gm, '').replace(/^###.*$/gm, '').trim();
|
const plainText = rawContent
|
||||||
const words = plainText.split(/\s+/).slice(0, 40);
|
.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 ? '...' : '');
|
const excerpt = words.join(' ') + (words.length === 40 ? '...' : '');
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,18 @@ const routeTranslations = {
|
||||||
const baseSlug = routeTranslations.news[locale] || routeTranslations.news.en;
|
const baseSlug = routeTranslations.news[locale] || routeTranslations.news.en;
|
||||||
|
|
||||||
const rawContent = post.body || "";
|
const rawContent = post.body || "";
|
||||||
const plainText = rawContent.replace(/^#.*$/gm, '').replace(/^###.*$/gm, '').trim();
|
const plainText = rawContent
|
||||||
const words = plainText.split(/\s+/).slice(0, 35);
|
.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 ? '...' : '');
|
const excerpt = words.join(' ') + (words.length === 35 ? '...' : '');
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue