add legacy image rewrite helper
src/lib/legacy-image.ts exports rewriteLegacyImageUrl(url) and rewriteLegacyImageUrlsInHtml(html) which translate WP origin URLs (https://www.broadcastbeat.com/wp-content/uploads/...) to local paths under /legacy/... served from the new persistent storage volume mounted at /app/public/legacy/. src/lib/legacy-image-map.json holds 3,856 URL→path entries built in Phase 2: 3,839 featured images (mostly converted to webp, q=85) plus 27 ad creatives plus the site logo. Use this helper at server-render time when emitting <img>/<Image> for imported WP articles, so the 707 MB on-host cache replaces external fetches to the origin.
This commit is contained in:
3858
src/lib/legacy-image-map.json
Normal file
3858
src/lib/legacy-image-map.json
Normal file
File diff suppressed because it is too large
Load Diff
34
src/lib/legacy-image.ts
Normal file
34
src/lib/legacy-image.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import map from "./legacy-image-map.json";
|
||||||
|
|
||||||
|
const LEGACY_MAP = map as Record<string, string>;
|
||||||
|
|
||||||
|
const LEGACY_HOSTS = [
|
||||||
|
"https://www.broadcastbeat.com",
|
||||||
|
"https://broadcastbeat.com",
|
||||||
|
"http://www.broadcastbeat.com",
|
||||||
|
"http://broadcastbeat.com",
|
||||||
|
];
|
||||||
|
|
||||||
|
export function rewriteLegacyImageUrl(url: string | null | undefined): string {
|
||||||
|
if (!url) return "";
|
||||||
|
// Direct map hit (canonical https://www.broadcastbeat.com/...)
|
||||||
|
const direct = LEGACY_MAP[url];
|
||||||
|
if (direct) return direct;
|
||||||
|
// Try alternate-host normalization
|
||||||
|
for (const host of LEGACY_HOSTS) {
|
||||||
|
if (url.startsWith(host)) {
|
||||||
|
const path = url.slice(host.length);
|
||||||
|
const canonical = `https://www.broadcastbeat.com${path}`;
|
||||||
|
const hit = LEGACY_MAP[canonical];
|
||||||
|
if (hit) return hit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rewriteLegacyImageUrlsInHtml(html: string): string {
|
||||||
|
return html.replace(
|
||||||
|
/(https?:\/\/(?:www\.)?broadcastbeat\.com\/wp-content\/uploads\/[^"'\s)]+)/g,
|
||||||
|
(m) => rewriteLegacyImageUrl(m),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user