Skip to content

Commit 854c3f3

Browse files
ralyodioclaude
andauthored
blog: also drop dead image from embedded JSON-LD (#49)
* blog: also drop dead image from embedded JSON-LD Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * dead-links: escape backslashes in host regex Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 1b45c79 commit 854c3f3

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎apps/web/src/lib/dead-links.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ export function stripDeadLinks(html: string): string {
2828
DEAD_IMAGE_HOSTS.some((h) => m.includes(h)) ? "" : m,
2929
);
3030
}
31+
// JSON-LD blocks embedded in the post: drop a dead "image" property.
32+
for (const h of DEAD_IMAGE_HOSTS) {
33+
const host = h.replace(/[\\.]/g, "\\$&");
34+
const val = `(?:\\[\\s*"https?:\\/\\/${host}[^"]*"(?:\\s*,\\s*"[^"]*")*\\s*\\]|"https?:\\/\\/${host}[^"]*")`;
35+
out = out.replace(new RegExp(`"image"\\s*:\\s*${val}\\s*,`, "g"), "");
36+
out = out.replace(new RegExp(`,\\s*"image"\\s*:\\s*${val}`, "g"), "");
37+
}
3138
if (DEAD_LINK_PREFIXES.some((p) => out.includes(p))) {
3239
out = out.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, (m, inner) =>
3340
DEAD_LINK_PREFIXES.some((p) => m.includes(`href="${p}`) || m.includes(`href='${p}`)) ? inner : m,

0 commit comments

Comments
 (0)