From 265fdba86ffd2514295d6cca6593d46f52bcb8e2 Mon Sep 17 00:00:00 2001 From: Tyler <26290074+thegitduck@users.noreply.github.com> Date: Tue, 11 Mar 2025 20:34:09 -0700 Subject: [PATCH] text from html --- src/_data/feeds.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/_data/feeds.ts b/src/_data/feeds.ts index 7c37959..dcfe589 100644 --- a/src/_data/feeds.ts +++ b/src/_data/feeds.ts @@ -74,6 +74,27 @@ const rssFeedUrls = [ // "https://www.webpro.nl/blog/feed.xml", ]; +function getTextFromHtml(htmlString: string): string { + if (!htmlString) { + return ""; + } + + // Remove HTML tags + const withoutTags = htmlString.replace(/<[^>]*>/g, " "); + + // Decode common HTML entities + const decoded = withoutTags + .replace(/ /g, " ") + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/"/g, '"') + .replace(/'/g, "'"); + + // Normalize whitespace + return decoded.replace(/\s+/g, " ").trim(); +} + // not all promises are resolved export async function getFeedData() { const addedUrls = new Set(); @@ -97,7 +118,7 @@ export async function getFeedData() { description: item.contentSnippet || item.content || "", link: item.link || "", pubDate: item.pubDate || "", - content: item.content || "", + content: item.content ? getTextFromHtml(item.content) : "", author: item.author || "", }); } -- 2.51.2