diff --git a/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift b/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift index af8b20be0..f8f5c8b86 100644 --- a/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift +++ b/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift @@ -40,6 +40,13 @@ public struct FeedSpecifier: Hashable, Sendable { return FeedSpecifier(title: "writing - rachelbythebay", urlString: feedURLString, source: .userEntered, orderFound: 0) } + // The blog page only advertises the master podcast feed in its , so the finder would + // otherwise miss the blog feed. + if url.isRelayFMBlogURL { + let feedURLString = "https://www.relay.fm/blog/feed" + return FeedSpecifier(title: "Relay FM Blog", urlString: feedURLString, source: .userEntered, orderFound: 0) + } + return nil } diff --git a/Modules/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift b/Modules/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift index 8d43fc7e8..3e503a19c 100644 --- a/Modules/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift +++ b/Modules/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift @@ -15,4 +15,13 @@ final class FeedFinderTests: XCTestCase { let feedFinder = FeedFinder() XCTAssertNotNil(feedFinder) } + + func testKnownFeedSpecifierForRelayFMBlog() throws { + let specifier = FeedSpecifier.knownFeedSpecifier(url: URL(string: "https://www.relay.fm/blog")!) + XCTAssertEqual(specifier?.urlString, "https://www.relay.fm/blog/feed") + } + + func testKnownFeedSpecifierIgnoresRelayFMRoot() throws { + XCTAssertNil(FeedSpecifier.knownFeedSpecifier(url: URL(string: "https://www.relay.fm")!)) + } } diff --git a/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift b/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift index 304b532fe..0aae2aaa2 100644 --- a/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift +++ b/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift @@ -15,6 +15,7 @@ nonisolated public struct SpecialCase { public static let openRSSOrgHostName = "openrss.org" public static let youtubeHostName = "youtube.com" public static let redditHostName = "reddit.com" + public static let relayFMHostName = "relay.fm" public static func urlStringContainSpecialCase(_ urlString: String, _ specialCases: [String]) -> Bool { let lowerURLString = urlString.lowercased(with: localeForLowercasing) @@ -84,6 +85,16 @@ nonisolated extension URL { public var isRedditURL: Bool { SpecialCase.urlStringMatchesDomain(absoluteString, [SpecialCase.redditHostName]) } + + /// The Relay FM blog, specifically — not the whole relay.fm domain (its root advertises the master + /// podcast feed). Matches the /blog index and /blog/ pages. + public var isRelayFMBlogURL: Bool { + guard SpecialCase.urlStringMatchesDomain(absoluteString, [SpecialCase.relayFMHostName]) else { + return false + } + let path = path() + return path == "/blog" || path.hasPrefix("/blog/") + } } nonisolated extension Set where Element == URL { diff --git a/Modules/RSWeb/Tests/RSWebTests/SpecialCasesTests.swift b/Modules/RSWeb/Tests/RSWebTests/SpecialCasesTests.swift index c0e5bd3ae..c1086d512 100644 --- a/Modules/RSWeb/Tests/RSWebTests/SpecialCasesTests.swift +++ b/Modules/RSWeb/Tests/RSWebTests/SpecialCasesTests.swift @@ -23,4 +23,18 @@ struct SpecialCasesTests { #expect(!URL(string: "https://reddit.com.evil.example/feed")!.isRedditURL) #expect(!URL(string: "https://example.com/r/reddit.com")!.isRedditURL) } + + @Test func isRelayFMBlogURLMatchesBlog() { + #expect(URL(string: "https://www.relay.fm/blog")!.isRelayFMBlogURL) + #expect(URL(string: "http://relay.fm/blog")!.isRelayFMBlogURL) + #expect(URL(string: "https://www.relay.fm/blog/")!.isRelayFMBlogURL) + #expect(URL(string: "https://www.relay.fm/blog/some-post")!.isRelayFMBlogURL) + } + + @Test func isRelayFMBlogURLRejectsNonBlog() { + #expect(!URL(string: "https://relay.fm")!.isRelayFMBlogURL) // root → master feed + #expect(!URL(string: "http://relay.fm/master/feed")!.isRelayFMBlogURL) + #expect(!URL(string: "https://www.relay.fm/blogsomething")!.isRelayFMBlogURL) + #expect(!URL(string: "https://relay.fm.evil.example/blog")!.isRelayFMBlogURL) // host check + } }