diff --git a/src/lib/articles/legacy-source.ts b/src/lib/articles/legacy-source.ts
index 3fa45e8..ca6f878 100644
--- a/src/lib/articles/legacy-source.ts
+++ b/src/lib/articles/legacy-source.ts
@@ -1,6 +1,6 @@
import { createClient } from "@supabase/supabase-js";
import type { Article } from "./types";
-import { rewriteLegacyImageUrl, rewriteLegacyImageUrlsInHtml } from "@/lib/legacy-image";
+import { rewriteLegacyImageUrl, cleanLegacyImages } from "@/lib/legacy-image";
const SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const SUPABASE_ANON = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!;
@@ -128,7 +128,7 @@ function rowToArticle(row: ImportedPostRow, section: Section = "news"): Article
const image = row.featured_image
? rewriteLegacyImageUrl(row.featured_image)
: FALLBACK_IMAGE;
- const content = rewriteLegacyImageUrlsInHtml(row.content || "");
+ const content = cleanLegacyImages(row.content || "");
const author = row.author_name || "Broadcast Beat";
return {
slug: row.wp_slug,
diff --git a/src/lib/legacy-image.ts b/src/lib/legacy-image.ts
index 1479306..7fb59db 100644
--- a/src/lib/legacy-image.ts
+++ b/src/lib/legacy-image.ts
@@ -32,3 +32,40 @@ export function rewriteLegacyImageUrlsInHtml(html: string): string {
(m) => rewriteLegacyImageUrl(m),
);
}
+
+/**
+ * Strip
, , and their wrapping / tags whose src
+ * still points at the dead WP host AFTER rewriteLegacyImageUrl ran. These
+ * load 404s in the browser and hurt SEO; better to remove than to leave
+ * broken image icons. Tags whose src is anything else are left alone.
+ */
+export function stripDeadLegacyImages(html: string): string {
+ if (!html) return html;
+
+ // Match
tags whose src still hits the dead WP host.
+ const DEAD_HOST_RE = /https?:\/\/(?:www\.)?broadcastbeat\.com\/wp-content\/uploads\//i;
+
+ // Drop entire ... blocks whose only inner content is a
+ // dead-image
. Preserves figures that wrap working images.
+ let out = html.replace(/]*>([\s\S]*?)<\/figure>/gi, (full, inner) => {
+ if (!/
]*\bsrc\s*=\s*["'][^"']*broadcastbeat\.com\/wp-content\/uploads\/[^"']*["']/i.test(inner)) return full;
+ // figure contains a dead image — drop entirely
+ return "";
+ });
+
+ // Drop …
… wrappers
+ out = out.replace(/]*>\s*
]*\bsrc\s*=\s*["'][^"']*broadcastbeat\.com\/wp-content\/uploads\/[^"']*["'][^>]*\/?>\s*<\/a>/gi, "");
+
+ // Drop bare
+ out = out.replace(/
]*\bsrc\s*=\s*["'][^"']*broadcastbeat\.com\/wp-content\/uploads\/[^"']*["'][^>]*\/?>/gi, "");
+
+ // Drop empty left over after image removal.
+ out = out.replace(/]*>\s*(?:]*>\s*<\/figcaption>\s*)?<\/figure>/gi, "");
+
+ return out;
+}
+
+/** One-call helper: rewrite mapped URLs, then strip anything still dead. */
+export function cleanLegacyImages(html: string): string {
+ return stripDeadLegacyImages(rewriteLegacyImageUrlsInHtml(html));
+}