reduce bounce rate
This commit is contained in:
@@ -37,6 +37,41 @@ function dedupe(items: ContentItem[]): ContentItem[] {
|
||||
return out;
|
||||
}
|
||||
|
||||
function normalizeSpotifyEpisodeUrl(value: string): string | undefined {
|
||||
const v = (value || "").trim();
|
||||
if (!v) return undefined;
|
||||
|
||||
if (v.startsWith("https://open.spotify.com/episode/")) return v;
|
||||
if (v.startsWith("https://open.spotify.com/embed/episode/")) {
|
||||
return v.replace("/embed/episode/", "/episode/");
|
||||
}
|
||||
|
||||
if (v.startsWith("spotify:episode:")) {
|
||||
const id = v.split(":")[2];
|
||||
if (!id) return undefined;
|
||||
return `https://open.spotify.com/episode/${id}`;
|
||||
}
|
||||
|
||||
if (/^[A-Za-z0-9]{10,30}$/.test(v)) {
|
||||
return `https://open.spotify.com/episode/${v}`;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function readPodcastSpotifyOverrideMap(logFn: (msg: string) => void) {
|
||||
const mapPath = path.join(process.cwd(), "content", "podcast-spotify-map.json");
|
||||
try {
|
||||
const raw = await fs.readFile(mapPath, "utf8");
|
||||
const parsed = JSON.parse(raw) as Record<string, string>;
|
||||
if (!parsed || typeof parsed !== "object") return undefined;
|
||||
return parsed;
|
||||
} catch {
|
||||
logFn("Podcast: spotify override map not found (content/podcast-spotify-map.json)");
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const cfg = getIngestConfigFromEnv(process.env);
|
||||
const generatedAt = new Date().toISOString();
|
||||
@@ -101,6 +136,23 @@ async function main() {
|
||||
);
|
||||
log(`Podcast: RSS ${cached ? "cache" : "live"} (${items.length} items)`);
|
||||
log(`Podcast: RSS ok (${items.length} items)`);
|
||||
|
||||
const overrideMap = await readPodcastSpotifyOverrideMap(log);
|
||||
if (overrideMap) {
|
||||
let overridden = 0;
|
||||
for (const it of items) {
|
||||
if (it.source !== "podcast") continue;
|
||||
const mapped = overrideMap[it.id] || overrideMap[it.url];
|
||||
const nextUrl = mapped ? normalizeSpotifyEpisodeUrl(mapped) : undefined;
|
||||
if (!nextUrl) continue;
|
||||
it.url = nextUrl;
|
||||
overridden++;
|
||||
}
|
||||
if (overridden > 0) {
|
||||
log(`Podcast: applied Spotify URL overrides (${overridden} items)`);
|
||||
}
|
||||
}
|
||||
|
||||
all.push(...items);
|
||||
} catch (e) {
|
||||
log(`Podcast: RSS failed (${String(e)})`);
|
||||
|
||||
Reference in New Issue
Block a user