Fix blog excerpt rendering: remove shortcodes and decode HTML entities

- Add decodeExcerptEntities() to handle —, …, smart quotes, etc.
- Add removeShortcodes() to strip [caption] and other WordPress shortcodes
- Regenerate blog-posts.json and pages.json with cleaned excerpts

Fixes issue where [caption] tags and raw HTML entities appeared in blog listings.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-02-05 13:46:20 +00:00
parent 9cc37beadb
commit 204679b740
3 changed files with 143 additions and 101 deletions

View File

@ -119,10 +119,52 @@ function cleanContent(html) {
return clean;
}
// Decode HTML entities for excerpts
function decodeExcerptEntities(text) {
return text
// Common HTML entities
.replace(/&mdash;/g, '—')
.replace(/&ndash;/g, '')
.replace(/&hellip;/g, '...')
.replace(/&rsquo;/g, "'")
.replace(/&lsquo;/g, "'")
.replace(/&rdquo;/g, '"')
.replace(/&ldquo;/g, '"')
.replace(/&nbsp;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#39;/g, "'")
.replace(/&#8217;/g, "'")
.replace(/&#8216;/g, "'")
.replace(/&#8220;/g, '"')
.replace(/&#8221;/g, '"')
.replace(/&#8212;/g, '—')
.replace(/&#8211;/g, '')
.replace(/&#8230;/g, '...');
}
// Remove WordPress-style shortcodes
function removeShortcodes(text) {
// Remove [caption]...[/caption] shortcodes
let clean = text.replace(/\[caption[^\]]*\](.*?)\[\/caption\]/gi, '$1');
// Remove other common shortcodes
clean = clean.replace(/\[\/?[a-z_]+[^\]]*\]/gi, '');
return clean;
}
// Extract first paragraph as excerpt
function extractExcerpt(content, maxLength = 200) {
// First decode HTML entities in the raw content
let text = decodeExcerptEntities(content);
// Remove WordPress shortcodes
text = removeShortcodes(text);
// Remove HTML tags
const text = content.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
text = text.replace(/<[^>]+>/g, ' ');
// Clean up whitespace
text = text.replace(/\s+/g, ' ').trim();
if (text.length <= maxLength) return text;
return text.substring(0, maxLength).replace(/\s+\S*$/, '') + '...';
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long