Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/feed-discovery/src/feed-discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe("feed parsing", () => {
expect(result.sampleItems[0]).toMatchObject({ title: "Launch tiny products", url: "https://example.com/post" });
});

it("detects podcast RSS feeds from item enclosures", () => {
const result = parseFeedDocument(
"https://example.com/podcast.xml",
`<?xml version="1.0"?><rss version="2.0"><channel><title>Audio Show</title><link>https://example.com</link><item><title>Episode 1</title><enclosure url="https://example.com/episode-1.mp3" type="audio/mpeg" length="12345" /></item></channel></rss>`
);

expect(result.ok).toBe(true);
expect(result.kind).toBe("podcast");
});

it("parses Atom and JSON Feed documents", () => {
const atom = parseFeedDocument("https://example.com/atom.xml", `<feed><title>Atom Feed</title><entry><title>Entry</title><updated>2026-06-09T00:00:00Z</updated></entry></feed>`);
const json = parseFeedDocument("https://example.com/feed.json", JSON.stringify({ version: "https://jsonfeed.org/version/1.1", title: "JSON Feed", items: [{ title: "Item", url: "https://example.com/item" }] }), "application/feed+json");
Expand Down
21 changes: 19 additions & 2 deletions plugins/feed-discovery/src/feed-parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function parseRss(feedUrl: string, rss: Record<string, unknown>): ValidationResu
title: title || "Untitled RSS Feed",
description: stringValue(channel.description),
homepageUrl: linkValue(channel.link),
kind: detectRssKind(channel),
kind: detectRssKind(channel, items),
language: stringValue(channel.language),
imageUrl: imageValue(channel.image),
lastPublishedAt: newestDate([stringValue(channel.lastBuildDate), stringValue(channel.pubDate), ...sampleItems.map((item) => item.publishedAt)]),
Expand Down Expand Up @@ -132,13 +132,30 @@ function parseAtom(feedUrl: string, feed: Record<string, unknown>): ValidationRe
};
}

function detectRssKind(channel: Record<string, unknown>): FeedKind {
function detectRssKind(channel: Record<string, unknown>, items: Record<string, unknown>[]): FeedKind {
if (channel.itunes || channel["itunes:author"] || channel.enclosure) {
return "podcast";
}
if (items.some(hasPodcastEnclosure)) {
return "podcast";
}
return "blog";
}

function hasPodcastEnclosure(item: Record<string, unknown>) {
return asArray(item.enclosure)
.filter(isRecord)
.some((enclosure) => {
const type = stringValue(enclosure.type)?.toLowerCase();
const url = stringValue(enclosure.url);
return (
type?.startsWith("audio/") ||
type?.startsWith("video/") ||
/\.(mp3|m4a|mp4|m4v|ogg|oga|wav|aac|flac)(?:[?#].*)?$/i.test(url ?? "")
);
});
}

function imageValue(value: unknown) {
if (isRecord(value)) {
return stringValue(value.url);
Expand Down
Loading