From b0ef44d08f3cb9197454eb3918e6af98a7616dd5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 14 Apr 2026 15:24:44 -0700 Subject: [PATCH 1/4] Parse channel image in RSS, Atom, and RSS-in-JSON feeds. We hope that they are square these days. Fixes #5258. --- Modules/RSParser/Sources/ObjC/RSAtomParser.m | 28 +++++++++++++++++-- Modules/RSParser/Sources/ObjC/RSParsedFeed.h | 3 +- Modules/RSParser/Sources/ObjC/RSParsedFeed.m | 7 +++-- Modules/RSParser/Sources/ObjC/RSRSSParser.m | 11 +++++++- .../Swift/Feeds/JSON/RSSInJSONParser.swift | 7 ++++- .../Feeds/XML/RSParsedFeedTransformer.swift | 2 +- .../Tests/RSParserTests/AtomParserTests.swift | 6 ++++ .../Tests/RSParserTests/RSSParserTests.swift | 14 ++++++++++ 8 files changed, 69 insertions(+), 9 deletions(-) diff --git a/Modules/RSParser/Sources/ObjC/RSAtomParser.m b/Modules/RSParser/Sources/ObjC/RSAtomParser.m index 307e15b25..a11090d3f 100755 --- a/Modules/RSParser/Sources/ObjC/RSAtomParser.m +++ b/Modules/RSParser/Sources/ObjC/RSAtomParser.m @@ -43,7 +43,8 @@ @property (nonatomic) RSParsedAuthor *rootAuthor; @property (nonatomic, readonly) NSDate *currentDate; @property (nonatomic) NSString *language; -@property (nonatomic) BOOL isDaringFireball; // Special case — sometimes permalink and external link are swapped. +@property (nonatomic) NSString *iconURLString; +@property (nonatomic) BOOL isDaringFireball; // Special case— sometimes permalink and external link are swapped. @end @@ -85,7 +86,7 @@ [self parse]; - RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.title homepageURLString:self.homepageURLString language:self.language articles:self.articles]; + RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.title homepageURLString:self.homepageURLString iconURL:self.iconURLString language:self.language articles:self.articles]; return parsedFeed; } @@ -210,6 +211,12 @@ static const NSInteger kEnclosureLength = 10; static const char *kLength = "length"; static const NSInteger kLengthLength = 7; +static const char *kIcon = "icon"; +static const NSInteger kIconLength = 5; + +static const char *kLogo = "logo"; +static const NSInteger kLogoLength = 5; + #pragma mark - Parsing - (void)parse { @@ -657,6 +664,23 @@ static NSString *httpURLPrefix = @"http://"; [self addFeedTitle]; } + else if (!self.parsingArticle && !self.parsingSource && RSSAXEqualTags(localName, kIcon, kIconLength)) { + NSString *urlString = [self currentString]; + if (!RSParserStringIsEmpty(urlString)) { + self.iconURLString = urlString; + } + } + + else if (!self.parsingArticle && !self.parsingSource && RSSAXEqualTags(localName, kLogo, kLogoLength)) { + // Use logo as fallback when icon isn’t specified + if (!self.iconURLString) { + NSString *urlString = [self currentString]; + if (!RSParserStringIsEmpty(urlString)) { + self.iconURLString = urlString; + } + } + } + [self.attributesStack removeLastObject]; } diff --git a/Modules/RSParser/Sources/ObjC/RSParsedFeed.h b/Modules/RSParser/Sources/ObjC/RSParsedFeed.h index 61de4e853..71dee2952 100755 --- a/Modules/RSParser/Sources/ObjC/RSParsedFeed.h +++ b/Modules/RSParser/Sources/ObjC/RSParsedFeed.h @@ -12,11 +12,12 @@ @interface RSParsedFeed : NSObject -- (nonnull instancetype)initWithURLString:(NSString * _Nonnull)urlString title:(NSString * _Nullable)title homepageURLString:(NSString * _Nullable)homepageURLString language:(NSString * _Nullable)language articles:(NSArray * _Nonnull)articles; +- (nonnull instancetype)initWithURLString:(NSString * _Nonnull)urlString title:(NSString * _Nullable)title homepageURLString:(NSString * _Nullable)homepageURLString iconURL:(NSString * _Nullable)iconURL language:(NSString * _Nullable)language articles:(NSArray * _Nonnull)articles; @property (nonatomic, readonly, nonnull) NSString *urlString; @property (nonatomic, readonly, nullable) NSString *title; @property (nonatomic, readonly, nullable) NSString *homepageURLString; +@property (nonatomic, readonly, nullable) NSString *iconURL; @property (nonatomic, readonly, nullable) NSString *language; @property (nonatomic, readonly, nonnull) NSSet *articles; diff --git a/Modules/RSParser/Sources/ObjC/RSParsedFeed.m b/Modules/RSParser/Sources/ObjC/RSParsedFeed.m index 9035c1862..45b896c67 100755 --- a/Modules/RSParser/Sources/ObjC/RSParsedFeed.m +++ b/Modules/RSParser/Sources/ObjC/RSParsedFeed.m @@ -12,19 +12,20 @@ @implementation RSParsedFeed -- (instancetype)initWithURLString:(NSString *)urlString title:(NSString *)title homepageURLString:(NSString *)homepageURLString language:(NSString *)language articles:(NSSet *)articles { +- (instancetype)initWithURLString:(NSString *)urlString title:(NSString *)title homepageURLString:(NSString *)homepageURLString iconURL:(NSString *)iconURL language:(NSString *)language articles:(NSSet *)articles { self = [super init]; if (!self) { return nil; } - + _urlString = urlString; _title = title; _homepageURLString = homepageURLString; + _iconURL = iconURL; _language = language; _articles = articles; - + return self; } diff --git a/Modules/RSParser/Sources/ObjC/RSRSSParser.m b/Modules/RSParser/Sources/ObjC/RSRSSParser.m index e3e26cdd4..0d900aa84 100755 --- a/Modules/RSParser/Sources/ObjC/RSRSSParser.m +++ b/Modules/RSParser/Sources/ObjC/RSRSSParser.m @@ -33,6 +33,7 @@ @property (nonatomic) BOOL parsingAuthor; @property (nonatomic, readonly) RSParsedArticle *currentArticle; @property (nonatomic) BOOL parsingChannelImage; +@property (nonatomic) NSString *channelImageURLString; @property (nonatomic, readonly) NSDate *currentDate; @property (nonatomic) BOOL endRSSFound; @property (nonatomic) NSString *homepageURLString; @@ -77,7 +78,7 @@ [self parse]; - RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.title homepageURLString:self.homepageURLString language:self.language articles:self.articles]; + RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.title homepageURLString:self.homepageURLString iconURL:self.channelImageURLString language:self.language articles:self.articles]; return parsedFeed; } @@ -452,6 +453,10 @@ static const NSInteger kLanguageLength = 9; if (!self.parsingChannelImage) { [self.parser beginStoringCharacters]; } + else if (!prefix && RSSAXEqualTags(localName, kURL, kURLLength)) { + // Channel image URL + [self.parser beginStoringCharacters]; + } } @@ -469,6 +474,10 @@ static const NSInteger kLanguageLength = 9; self.endRSSFound = YES; } + else if (self.parsingChannelImage && !self.parsingArticle && RSSAXEqualTags(localName, kURL, kURLLength)) { + self.channelImageURLString = [self currentString]; + } + else if (RSSAXEqualTags(localName, kImage, kImageLength)) { self.parsingChannelImage = NO; } diff --git a/Modules/RSParser/Sources/Swift/Feeds/JSON/RSSInJSONParser.swift b/Modules/RSParser/Sources/Swift/Feeds/JSON/RSSInJSONParser.swift index 7865c27b4..baaeabdff 100644 --- a/Modules/RSParser/Sources/Swift/Feeds/JSON/RSSInJSONParser.swift +++ b/Modules/RSParser/Sources/Swift/Feeds/JSON/RSSInJSONParser.swift @@ -50,9 +50,14 @@ public struct RSSInJSONParser { let feedDescription = channelObject["description"] as? String let feedLanguage = channelObject["language"] as? String + var iconURL: String? + if let imageObject = channelObject["image"] as? JSONDictionary { + iconURL = imageObject["url"] as? String + } + let items = parseItems(itemsObject!, parserData.url) - return ParsedFeed(type: .rssInJSON, title: title, homePageURL: homePageURL, feedURL: feedURL, language: feedLanguage, feedDescription: feedDescription, nextURL: nil, iconURL: nil, faviconURL: nil, authors: nil, expired: false, hubs: nil, items: items) + return ParsedFeed(type: .rssInJSON, title: title, homePageURL: homePageURL, feedURL: feedURL, language: feedLanguage, feedDescription: feedDescription, nextURL: nil, iconURL: iconURL, faviconURL: nil, authors: nil, expired: false, hubs: nil, items: items) } catch { throw error } } diff --git a/Modules/RSParser/Sources/Swift/Feeds/XML/RSParsedFeedTransformer.swift b/Modules/RSParser/Sources/Swift/Feeds/XML/RSParsedFeedTransformer.swift index e03537449..a03c84a37 100644 --- a/Modules/RSParser/Sources/Swift/Feeds/XML/RSParsedFeedTransformer.swift +++ b/Modules/RSParser/Sources/Swift/Feeds/XML/RSParsedFeedTransformer.swift @@ -21,7 +21,7 @@ struct RSParsedFeedTransformer { static func parsedFeed(_ rsParsedFeed: RSParsedFeed) -> ParsedFeed { let items = parsedItems(rsParsedFeed.articles) - return ParsedFeed(type: .rss, title: rsParsedFeed.title, homePageURL: rsParsedFeed.homepageURLString, feedURL: rsParsedFeed.urlString, language: rsParsedFeed.language, feedDescription: nil, nextURL: nil, iconURL: nil, faviconURL: nil, authors: nil, expired: false, hubs: nil, items: items) + return ParsedFeed(type: .rss, title: rsParsedFeed.title, homePageURL: rsParsedFeed.homepageURLString, feedURL: rsParsedFeed.urlString, language: rsParsedFeed.language, feedDescription: nil, nextURL: nil, iconURL: rsParsedFeed.iconURL, faviconURL: nil, authors: nil, expired: false, hubs: nil, items: items) } } diff --git a/Modules/RSParser/Tests/RSParserTests/AtomParserTests.swift b/Modules/RSParser/Tests/RSParserTests/AtomParserTests.swift index b98a7ae05..c27af43e7 100644 --- a/Modules/RSParser/Tests/RSParserTests/AtomParserTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/AtomParserTests.swift @@ -186,6 +186,12 @@ final class AtomParserTests: XCTestCase { } } + func testFeedIconURL() { + let d = parserData("root-author", "atom", "https://fvsch.com/feed.xml") + let parsedFeed = try! FeedParser.parse(d)! + XCTAssertEqual(parsedFeed.iconURL, "https://fvsch.com/assets/images/icon.png?v=ql0r5y") + } + func testAuthorAtRoot() { let d = parserData("root-author", "atom", "https://fvsch.com/feed.xml") let parsedFeed = try! FeedParser.parse(d)! diff --git a/Modules/RSParser/Tests/RSParserTests/RSSParserTests.swift b/Modules/RSParser/Tests/RSParserTests/RSSParserTests.swift index 247070c24..113f588d9 100644 --- a/Modules/RSParser/Tests/RSParserTests/RSSParserTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/RSSParserTests.swift @@ -191,6 +191,20 @@ final class RSSParserTests: XCTestCase { } } + func testFeedIconURL() { + let d = parserData("KatieFloyd", "rss", "http://katiefloyd.com/") + let parsedFeed = try! FeedParser.parse(d)! + XCTAssertEqual(parsedFeed.iconURL, "https://static.feedpress.it/logo/katiefloyd.png") + } + + func testFeedIconURLNotSetByItemLevelImages() { + // aktuality.rss has elements inside s, not at the channel level. + // These should not be treated as the feed icon. + let d = parserData("aktuality", "rss", "https://www.aktuality.sk/") + let parsedFeed = try! FeedParser.parse(d)! + XCTAssertNil(parsedFeed.iconURL) + } + func testMedscapeExternalURLs() { let d = parserData("medscape", "rss", "https://www.medscape.com/cx/rssfeeds/2674.xml") let parsedFeed = try! FeedParser.parse(d)! From 328e70dd726cd53ab57af644d6a429eb7c3dcd11 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 14 Apr 2026 16:06:51 -0700 Subject: [PATCH 2/4] Always use aspect fit with images in the timeline. --- Mac/MainWindow/IconView.swift | 15 +++++++-------- iOS/IconView.swift | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Mac/MainWindow/IconView.swift b/Mac/MainWindow/IconView.swift index 0795d8025..8616a9d72 100644 --- a/Mac/MainWindow/IconView.swift +++ b/Mac/MainWindow/IconView.swift @@ -115,21 +115,20 @@ private extension IconView { let imageSize = image.size let viewSize = bounds.size + if imageSize.height == imageSize.width { - if imageSize.height >= viewSize.height * 0.75 { - // Close enough to viewSize to scale up the image. - return NSRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) - } - let offset = floor((viewSize.height - imageSize.height) / 2.0) - return NSRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height) - } else if imageSize.height > imageSize.width { + return NSRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) + } + + // Non-square: aspect fit — scale to fill one dimension, center in the other + if imageSize.height > imageSize.width { let factor = viewSize.height / imageSize.height let width = imageSize.width * factor let originX = floor((viewSize.width - width) / 2.0) return NSRect(x: originX, y: 0.0, width: width, height: viewSize.height) } - // Wider than tall: imageSize.width > imageSize.height + // Wider than tall let factor = viewSize.width / imageSize.width let height = imageSize.height * factor let originY = floor((viewSize.height - height) / 2.0) diff --git a/iOS/IconView.swift b/iOS/IconView.swift index ef18e6496..9e78f16d0 100644 --- a/iOS/IconView.swift +++ b/iOS/IconView.swift @@ -91,21 +91,20 @@ private extension IconView { let imageSize = image.size let viewSize = bounds.size + if imageSize.height == imageSize.width { - if imageSize.height >= viewSize.height * 0.75 { - // Close enough to viewSize to scale up the image. - return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) - } - let offset = floor((viewSize.height - imageSize.height) / 2.0) - return CGRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height) - } else if imageSize.height > imageSize.width { + return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) + } + + // Non-square: aspect fit — scale to fill one dimension, center in the other + if imageSize.height > imageSize.width { let factor = viewSize.height / imageSize.height let width = imageSize.width * factor let originX = floor((viewSize.width - width) / 2.0) return CGRect(x: originX, y: 0.0, width: width, height: viewSize.height) } - // Wider than tall: imageSize.width > imageSize.height + // Wider than tall let factor = viewSize.width / imageSize.width let height = imageSize.height * factor let originY = floor((viewSize.height - height) / 2.0) From 395b258290e3475d717ed5726ef1dd5670a2c76f Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 14 Apr 2026 19:06:24 -0700 Subject: [PATCH 3/4] Add a way to specify some domains the app should ignore the feed-specified image. --- Shared/Images/FeedIconDownloader.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Shared/Images/FeedIconDownloader.swift b/Shared/Images/FeedIconDownloader.swift index 3c4a4eceb..3fe48d388 100644 --- a/Shared/Images/FeedIconDownloader.swift +++ b/Shared/Images/FeedIconDownloader.swift @@ -87,7 +87,7 @@ extension Notification.Name { } @MainActor func checkFeedIconURL() { - if let iconURL = feed.iconURL { + if let iconURL = feed.iconURL, !Self.shouldIgnoreFeedIconURL(feed) { icon(forURL: iconURL, feed: feed) { (image) in Task { @MainActor in if self.cache[feed] != nil { @@ -141,6 +141,10 @@ private extension FeedIconDownloader { static let specialCasesToSkip = ["macsparky.com", "xkcd.com", SpecialCase.rachelByTheBayHostName, SpecialCase.openRSSOrgHostName] + // Domains where the feed-specified icon URL should be ignored, + // falling back to the homepage icon lookup instead. + static let domainsToIgnoreFeedIconURL: [String] = ["stratechery.com", "propublica.org", "substack.com"] + static func shouldSkipDownloadingFeedIcon(feed: Feed) -> Bool { shouldSkipDownloadingFeedIcon(feed.url) } @@ -149,6 +153,13 @@ private extension FeedIconDownloader { SpecialCase.urlStringContainSpecialCase(urlString, specialCasesToSkip) } + static func shouldIgnoreFeedIconURL(_ feed: Feed) -> Bool { + guard !domainsToIgnoreFeedIconURL.isEmpty else { + return false + } + return SpecialCase.urlStringContainSpecialCase(feed.url, domainsToIgnoreFeedIconURL) + } + func icon(forHomePageURL homePageURL: String, feed: Feed, _ resultBlock: @escaping @MainActor (RSImage?, String?) -> Void) { if Self.shouldSkipDownloadingFeedIcon(homePageURL) { resultBlock(nil, nil) From ffe930ad2c7a5f54cdc89434991aecc26291c3bc Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 14 Apr 2026 19:23:58 -0700 Subject: [PATCH 4/4] Add some special case feed icons. --- Shared/Images/FeedIconDownloader.swift | 42 +++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Shared/Images/FeedIconDownloader.swift b/Shared/Images/FeedIconDownloader.swift index 3fe48d388..305111cd7 100644 --- a/Shared/Images/FeedIconDownloader.swift +++ b/Shared/Images/FeedIconDownloader.swift @@ -60,9 +60,29 @@ extension Notification.Name { return cachedImage } - if let homePageURLString = feed.homePageURL, let homePageURL = URL(string: homePageURLString), homePageURL.host == "nnw.ranchero.com" || homePageURL.host == "netnewswire.blog" { + if let homePageURLString = feed.homePageURL, let homePageURL = URL(string: homePageURLString) { + if homePageURL.host == "nnw.ranchero.com" || homePageURL.host == "netnewswire.blog" || homePageURL.host == "services.netnewswire.com" { + return IconImage.nnwFeedIcon + } + } + if feed.url.hasPrefix("https://ranchero.com/downloads/netnewswire") { return IconImage.nnwFeedIcon } + + if let knownIconURL = Self.knownIconURL(for: feed) { + icon(forURL: knownIconURL, feed: feed) { image in + MainActor.assumeIsolated { + if self.cache[feed] != nil { + return + } + if let image { + self.cache[feed] = IconImage(image) + self.postFeedIconDidBecomeAvailableNotification(feed) + } + } + } + return nil + } if Self.shouldSkipDownloadingFeedIcon(feed: feed) { return nil } @@ -145,6 +165,13 @@ private extension FeedIconDownloader { // falling back to the homepage icon lookup instead. static let domainsToIgnoreFeedIconURL: [String] = ["stratechery.com", "propublica.org", "substack.com"] + // Domains with a known-good icon URL to use instead of the + // feed-specified icon or homepage lookup. + static let domainToIconURL: [String: String] = [ + "github.blog": "https://github.blog/wp-content/uploads/2019/01/cropped-github-favicon-512.png", + "github.com": "https://github.blog/wp-content/uploads/2019/01/cropped-github-favicon-512.png" + ] + static func shouldSkipDownloadingFeedIcon(feed: Feed) -> Bool { shouldSkipDownloadingFeedIcon(feed.url) } @@ -160,6 +187,19 @@ private extension FeedIconDownloader { return SpecialCase.urlStringContainSpecialCase(feed.url, domainsToIgnoreFeedIconURL) } + static func knownIconURL(for feed: Feed) -> String? { + guard !domainToIconURL.isEmpty else { + return nil + } + let lowerFeedURL = feed.url.lowercased(with: localeForLowercasing) + for (domain, iconURL) in domainToIconURL { + if lowerFeedURL.contains(domain) { + return iconURL + } + } + return nil + } + func icon(forHomePageURL homePageURL: String, feed: Feed, _ resultBlock: @escaping @MainActor (RSImage?, String?) -> Void) { if Self.shouldSkipDownloadingFeedIcon(homePageURL) { resultBlock(nil, nil)