From dd7d639659ac7611c0f0ad1b38ec26f4c26a9b83 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 20:36:59 -0800 Subject: [PATCH 1/8] Remove MainWindowSplitView subclass (drop the custom divider color in light mode). --- Mac/MainWindow/ColumnLayoutSplitView.swift | 2 +- Mac/MainWindow/MainWindowController.swift | 2 +- Mac/MainWindow/MainWindowSplitView.swift | 22 ---------------------- 3 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 Mac/MainWindow/MainWindowSplitView.swift diff --git a/Mac/MainWindow/ColumnLayoutSplitView.swift b/Mac/MainWindow/ColumnLayoutSplitView.swift index e8e0346a8..6be6f87cf 100644 --- a/Mac/MainWindow/ColumnLayoutSplitView.swift +++ b/Mac/MainWindow/ColumnLayoutSplitView.swift @@ -10,7 +10,7 @@ import AppKit /// The split between the timeline and the article view in column layout. /// On macOS 26 it extends under the sidebar, so the divider is drawn in the visible part only — otherwise the dimple is off-center. -final class ColumnLayoutSplitView: MainWindowSplitView { +final class ColumnLayoutSplitView: NSSplitView { override func drawDivider(in rect: NSRect) { super.drawDivider(in: rect.intersection(safeAreaRect)) diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index b9abbd3b7..aa63ae522 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -1270,7 +1270,7 @@ private extension MainWindowController { return (splitViewController, contentSplitViewController) } - func makeEmptySplitViewController(isVertical: Bool, splitView: NSSplitView = MainWindowSplitView()) -> NSSplitViewController { + func makeEmptySplitViewController(isVertical: Bool, splitView: NSSplitView = NSSplitView()) -> NSSplitViewController { let splitViewController = NSSplitViewController() splitViewController.splitView = splitView splitViewController.splitView.isVertical = isVertical diff --git a/Mac/MainWindow/MainWindowSplitView.swift b/Mac/MainWindow/MainWindowSplitView.swift deleted file mode 100644 index 952792aec..000000000 --- a/Mac/MainWindow/MainWindowSplitView.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// MainWindowSplitView.swift -// NetNewsWire -// -// Created by Brent Simmons on 11/7/26. -// Copyright © 2026 Ranchero Software. All rights reserved. -// - -import AppKit - -/// The main window’s split views. In light mode, the dividers are a little darker than the system’s. -class MainWindowSplitView: NSSplitView { - - private static let lightDividerColor = NSColor(srgbRed: 200 / 255, green: 200 / 255, blue: 200 / 255, alpha: 1) - - override var dividerColor: NSColor { - if effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua { - return super.dividerColor - } - return Self.lightDividerColor - } -} From 0937d656b6580cacc4528913dc333fe49b5c7bdd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 20:45:52 -0800 Subject: [PATCH 2/8] =?UTF-8?q?Add=20special=20case=20handling=20for=20fee?= =?UTF-8?q?ds=20where=20the=20title=20appears=20in=20article=20content.=20?= =?UTF-8?q?Add=20reactormag=E2=80=99s=20feed=20as=20first=20of=20those=20s?= =?UTF-8?q?pecial=20cases.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/Article Rendering/ArticleRenderer.swift | 7 ++++++- .../ArticleRenderingSpecialCases.swift | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 5b44bc19c..a25f409c6 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -263,7 +263,12 @@ private extension ArticleRenderer { return d } - d["title"] = title + // Reader view content comes from the web page, not the feed, so it keeps the title. + if extractedArticle == nil, ArticleRenderingSpecialCases.contentIncludesTitle(feedURL: article.feed?.url) { + d["title"] = "" + } else { + d["title"] = title + } d["preferred_link"] = article.preferredLink ?? "" if let externalLink = article.externalLink, externalLink != article.preferredLink { diff --git a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift index ecee8bf72..116688eb1 100644 --- a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift +++ b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift @@ -106,6 +106,16 @@ struct ArticleRenderingSpecialCases { return result } + private static let feedURLsWithTitleInContent = ["https://reactormag.com/feed/"] + + /// These feeds’ content starts with the article’s own styled title, so the article view doesn’t show a second one. + static func contentIncludesTitle(feedURL: String?) -> Bool { + guard let feedURL else { + return false + } + return feedURLsWithTitleInContent.contains(feedURL) + } + static func filterHTMLIfNeeded(baseURL: String, html: String) -> String { var filteredHTML = removeLocationHrefRedirectScripts(html) From bcd8717bd8100ceebeead0eb5109aa1cefddf489 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 20:49:16 -0800 Subject: [PATCH 3/8] Hide empty article title. --- Shared/Article Rendering/core.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Shared/Article Rendering/core.css b/Shared/Article Rendering/core.css index f6d20f7ae..bbfc1f2df 100644 --- a/Shared/Article Rendering/core.css +++ b/Shared/Article Rendering/core.css @@ -14,6 +14,12 @@ html { position: relative; } +/* No gap for an empty title: untitled articles, and feeds whose content includes the title. */ + +.articleTitle:has(a:empty) { + display: none; +} + pre, code { tab-size: 4; } From 191febbc2a3fb97bbace552b205d5813e64c88c6 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 21:13:56 -0800 Subject: [PATCH 4/8] Add special case to article renderer for adding additional CSS for feeds. --- Shared/Article Rendering/ArticleRenderer.swift | 6 +++++- .../ArticleRenderingSpecialCases.swift | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index a25f409c6..5b7cac07e 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -232,7 +232,11 @@ private extension ArticleRenderer { } private var articleCSS: String { - return try! MacroProcessor.renderedText(withTemplate: styleString(), substitutions: styleSubstitutions()) + let css = try! MacroProcessor.renderedText(withTemplate: styleString(), substitutions: styleSubstitutions()) + guard extractedArticle == nil, let feedSpecificCSS = ArticleRenderingSpecialCases.feedSpecificCSS(feedURL: article?.feed?.url) else { + return css + } + return css + "\n" + feedSpecificCSS } static var defaultStyleSheet: String = { diff --git a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift index 116688eb1..0d352a8e5 100644 --- a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift +++ b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift @@ -116,6 +116,24 @@ struct ArticleRenderingSpecialCases { return feedURLsWithTitleInContent.contains(feedURL) } + // Hide clutter in Reactor’s post header. + private static let reactorAdditionalCSS = """ + .post-hero-symbol, .post-hero-publish, .post-hero-caption-vertical, .post-hero-quick-access { + display: none; + } + """ + + private static let feedSpecificCSSByFeedURL = [ + "https://reactormag.com/feed/": reactorAdditionalCSS + ] + + static func feedSpecificCSS(feedURL: String?) -> String? { + guard let feedURL else { + return nil + } + return feedSpecificCSSByFeedURL[feedURL] + } + static func filterHTMLIfNeeded(baseURL: String, html: String) -> String { var filteredHTML = removeLocationHrefRedirectScripts(html) From f17f639a51724cc89105e4ad236c98628addce89 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 21:34:59 -0800 Subject: [PATCH 5/8] Avoid showing duplicate images when enclosure and article image are same but different size. --- .../ArticleRenderer+Enclosures.swift | 36 +++++++++---------- .../ArticleRenderer+PrimaryMedia.swift | 14 ++++++-- .../EnclosuresHTMLTests.swift | 10 ++++++ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderer+Enclosures.swift b/Shared/Article Rendering/ArticleRenderer+Enclosures.swift index b46451510..8a5b6913c 100644 --- a/Shared/Article Rendering/ArticleRenderer+Enclosures.swift +++ b/Shared/Article Rendering/ArticleRenderer+Enclosures.swift @@ -101,6 +101,24 @@ extension ArticleRenderer { return html } + /// The last two path components, lowercased, without a WordPress size suffix, Engadget size prefix, + /// or Brett Terpstra version number and crop marker. + /// Two components, since some sites name every image `original.jpg` in its own folder. + /// Ignores the host and query, since resized copies are often served through a resizing service. + static func imageIdentity(_ urlString: String) -> String? { + guard let url = URL(string: urlString) else { + return nil + } + let pathComponents = url.pathComponents.filter { $0 != "/" } + guard let lastPathComponent = pathComponents.last else { + return nil + } + let engadgetFileName = ArticleRenderingSpecialCases.removingEngadgetImagePrefix(lastPathComponent, imageURL: urlString) + let fileName = ArticleRenderingSpecialCases.removingBrettTerpstraImageSuffixes(engadgetFileName, imageURL: urlString).replacing(wordPressSizeSuffix, with: "") + let folderName = pathComponents.dropLast().suffix(1) + return (folderName + [fileName]).joined(separator: "/").lowercased() + } + } private extension ArticleRenderer { @@ -143,22 +161,4 @@ private extension ArticleRenderer { static func bodyContainsURL(_ body: String, _ url: String) -> Bool { body.contains(url) || body.contains(url.escapingSpecialXMLCharacters) } - - /// The last two path components, lowercased, without a WordPress size suffix, Engadget size prefix, - /// or Brett Terpstra version number and crop marker. - /// Two components, since some sites name every image `original.jpg` in its own folder. - /// Ignores the host and query, since resized copies are often served through a resizing service. - static func imageIdentity(_ urlString: String) -> String? { - guard let url = URL(string: urlString) else { - return nil - } - let pathComponents = url.pathComponents.filter { $0 != "/" } - guard let lastPathComponent = pathComponents.last else { - return nil - } - let engadgetFileName = ArticleRenderingSpecialCases.removingEngadgetImagePrefix(lastPathComponent, imageURL: urlString) - let fileName = ArticleRenderingSpecialCases.removingBrettTerpstraImageSuffixes(engadgetFileName, imageURL: urlString).replacing(wordPressSizeSuffix, with: "") - let folderName = pathComponents.dropLast().suffix(1) - return (folderName + [fileName]).joined(separator: "/").lowercased() - } } diff --git a/Shared/Article Rendering/ArticleRenderer+PrimaryMedia.swift b/Shared/Article Rendering/ArticleRenderer+PrimaryMedia.swift index 208a6cdf5..be56935e9 100644 --- a/Shared/Article Rendering/ArticleRenderer+PrimaryMedia.swift +++ b/Shared/Article Rendering/ArticleRenderer+PrimaryMedia.swift @@ -61,12 +61,13 @@ extension ArticleRenderer { /// The article image (JSON Feed `image`, `itunes:image`, or a sync service’s image), else the first image attachment, /// else the thumbnail (`media:thumbnail`, which Wired uses for its full-size lead image), unless it’s Blogger’s tiny crop. /// Nil when the body already has the image, or a resized copy of it at a different URL. - /// An attachment with the same URL supplies the dimensions and title. + /// An attachment with the same URL supplies the dimensions and title. An image attachment that’s a resized copy + /// of the article image is used in its place, so the enclosures don’t show the same picture again. static func primaryImage(imageLink: String?, thumbnailLink: String?, attachments: [Attachment]?, body: String, bodyImageIdentities: Set) -> Attachment? { let attachments = attachments ?? [] let image: Attachment? if let imageLink, !imageLink.isEmpty { - image = attachments.first { $0.url == imageLink } ?? imageAttachment(imageLink) + image = attachments.first { $0.url == imageLink } ?? resizedCopy(of: imageLink, attachments: attachments) ?? imageAttachment(imageLink) } else if let firstImageAttachment = attachments.first(where: { $0.displayMedium == .image }) { image = firstImageAttachment } else if let thumbnailLink, !thumbnailLink.isEmpty, !ArticleRenderingSpecialCases.isBloggerThumbnail(thumbnailLink) { @@ -109,6 +110,15 @@ private extension ArticleRenderer { attachment.displayMedium == .video || ArticleRenderingSpecialCases.youTubeEmbedURL(forAttachmentURL: attachment.url) != nil } + /// An image attachment of the same picture at a different size or host, as in Feedbin’s `og:image` + /// `…-768x432.jpg` and the feed’s enclosure `…-850x638.jpg`. + static func resizedCopy(of imageURL: String, attachments: [Attachment]) -> Attachment? { + guard let identity = imageIdentity(imageURL) else { + return nil + } + return attachments.first { $0.displayMedium == .image && imageIdentity($0.url) == identity } + } + static func imageAttachment(_ url: String) -> Attachment? { Attachment(url: url, mimeType: nil, title: nil, sizeInBytes: nil, durationInSeconds: nil, width: nil, height: nil, medium: .image) } diff --git a/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift b/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift index 8f867d01f..9574a2c83 100644 --- a/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift +++ b/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift @@ -50,6 +50,16 @@ import Articles #expect(ArticleRenderer.primaryImageHTML(primaryImage, articleTitle: nil) == "
\"Great
Great blue heron at Green Lake
") } + // Boston.com via Feedbin on 2026-12-02: Feedbin’s image is the page’s `og:image`, a resized copy of the enclosure. + @Test func primaryImageUsesEnclosureThatIsResizedCopy() throws { + let imageURL = "https://bdc2020.o0bc.com/wp-content/uploads/2026/12/School_Lunches_66852-6b10d0252704b-768x432.jpg" + let enclosureURL = "https://www.boston.com/wp-content/uploads/2026/12/School_Lunches_66852-6b10d0252704b-850x638.jpg" + let attachment = try #require(Attachment(url: enclosureURL, mimeType: "image/jpeg", title: nil, sizeInBytes: 88325, durationInSeconds: nil, width: nil, height: nil, medium: nil)) + let body = "

Federal officials are proposing new requirements for school lunches as part of an effort to combat obesity and other chronic health conditions

" + + #expect(ArticleRenderer.primaryImage(imageLink: imageURL, thumbnailLink: nil, attachments: [attachment], body: body, bodyImageIdentities: ArticleRenderer.bodyImageIdentities(body, baseURL: nil))?.url == enclosureURL) + } + // A feed that titles the image with the article’s title. @Test func primaryImageCaptionDroppedWhenSameAsArticleTitle() throws { let imageURL = "https://example.com/uploads/2026/11/heron.jpg" From 005ad5212a5ea0f4e690896f9a30a52347f0a335 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 21:38:56 -0800 Subject: [PATCH 6/8] Improve detection of image identity by removing "scaled" from name. --- .../Article Rendering/ArticleRenderer+Enclosures.swift | 4 ++-- Tests/NetNewsWireTests/EnclosuresHTMLTests.swift | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderer+Enclosures.swift b/Shared/Article Rendering/ArticleRenderer+Enclosures.swift index 8a5b6913c..c76b2d9c5 100644 --- a/Shared/Article Rendering/ArticleRenderer+Enclosures.swift +++ b/Shared/Article Rendering/ArticleRenderer+Enclosures.swift @@ -16,8 +16,8 @@ extension ArticleRenderer { private static let secondsPerMinute = 60 private static let secondsPerHour = 3600 - /// A WordPress resized copy’s suffix, as in `heron-1024x683.jpg`. - private static let wordPressSizeSuffix = #/-\d+x\d+(?=\.[A-Za-z0-9]+$)/# + /// A WordPress resized copy’s suffix, as in `heron-1024x683.jpg`, or a large upload’s scaled copy, as in `heron-scaled.jpg`. + private static let wordPressSizeSuffix = #/-(?:\d+x\d+|scaled)(?=\.[A-Za-z0-9]+$)/# /// Empty when there’s nothing to show. Skips attachments already in the body, including resized copies, /// since feeds often embed the same image they list as an enclosure. diff --git a/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift b/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift index 9574a2c83..f64c13ce6 100644 --- a/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift +++ b/Tests/NetNewsWireTests/EnclosuresHTMLTests.swift @@ -60,6 +60,16 @@ import Articles #expect(ArticleRenderer.primaryImage(imageLink: imageURL, thumbnailLink: nil, attachments: [attachment], body: body, bodyImageIdentities: ArticleRenderer.bodyImageIdentities(body, baseURL: nil))?.url == enclosureURL) } + // Boston.com via Feedbin on 2026-12-02: the `og:image` is WordPress’s scaled copy of a large upload. + @Test func primaryImageUsesEnclosureWhenImageIsScaledCopy() throws { + let imageURL = "https://www.boston.com/wp-content/uploads/2026/11/P6XAPG6ON7HAYE7E3SQUUDBCZM-6afc32a38c7d7-scaled.jpg" + let enclosureURL = "https://www.boston.com/wp-content/uploads/2026/11/P6XAPG6ON7HAYE7E3SQUUDBCZM-6afc32a38c7d7-850x638.jpg" + let attachment = try #require(Attachment(url: enclosureURL, mimeType: "image/jpeg", title: nil, sizeInBytes: nil, durationInSeconds: nil, width: nil, height: nil, medium: nil)) + let body = "

All 13 measles cases in Vermont are in Orleans County, which is located in the state’s northeast corner.

" + + #expect(ArticleRenderer.primaryImage(imageLink: imageURL, thumbnailLink: nil, attachments: [attachment], body: body, bodyImageIdentities: ArticleRenderer.bodyImageIdentities(body, baseURL: nil))?.url == enclosureURL) + } + // A feed that titles the image with the article’s title. @Test func primaryImageCaptionDroppedWhenSameAsArticleTitle() throws { let imageURL = "https://example.com/uploads/2026/11/heron.jpg" From f3eb190e7820ff52ea6b9d51fa84cba6b99c6ffc Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 21:52:39 -0800 Subject: [PATCH 7/8] Show Feedbin image instead of image enclosure. --- Shared/Article Rendering/ArticleRenderer.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 5b7cac07e..3247b9887 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -289,6 +289,10 @@ private extension ArticleRenderer { // The thumbnail is used only for [[primary_media]]. let bodyImageIdentities = Self.bodyImageIdentities(body, baseURL: baseURL) var attachments = article.attachments ?? [] + // Feedbin’s image is also the timeline thumbnail, so it’s shown instead of the feed’s image enclosure. + if article.account?.type == .feedbin, let imageLink = article.imageLink, !imageLink.isEmpty { + attachments.removeAll { $0.displayMedium == .image } + } var primaryMediaHTML = "" var primaryMediaURLs = Set() let hasPrimaryMedia = template().contains(Self.primaryMediaMacro) From 69acad4d06a48812aae6bbb57da2bddf07847efb Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Dec 2026 21:56:19 -0800 Subject: [PATCH 8/8] =?UTF-8?q?Add=20special=20case=20system=20for=20place?= =?UTF-8?q?holder=20images,=20so=20they=E2=80=99re=20not=20treated=20as=20?= =?UTF-8?q?thumbnails=20or=20as=20image=20to=20show=20in=20the=20article.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Images/ArticleThumbnailFinder.swift | 12 ++++++++++-- .../RSParser/HTML/SignificantImageFilter.swift | 15 ++++++++++++++- .../RSParserTests/HTML/HTMLImageParserTests.swift | 1 + Shared/Article Rendering/ArticleRenderer.swift | 14 +++++++++----- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift b/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift index f918ed6c7..9314bc9e7 100644 --- a/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift +++ b/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift @@ -71,7 +71,7 @@ extension Notification.Name { return chosenThumbnailURL.thumbnailURL } - let thumbnailURL = providedThumbnailURL(for: article, mode: mode) ?? cachedOrParsedHTMLThumbnailURLs(for: article).first { !hasFailed($0) } ?? usableProvidedURL(Self.normalizedURLString(article.rawThumbnailLink)) + let thumbnailURL = providedThumbnailURL(for: article, mode: mode) ?? cachedOrParsedHTMLThumbnailURLs(for: article).first { !hasFailed($0) } ?? usableProvidedURL(Self.thumbnailLink(article)) if chosenThumbnailURLs[mode, default: [:]].count >= Self.maxChosenThumbnailURLCount { chosenThumbnailURLs[mode] = nil } @@ -208,7 +208,7 @@ private extension ArticleThumbnailFinder { func providedThumbnailURL(for article: Article, mode: ThumbnailMode) -> String? { switch mode { case .small: - usableProvidedURL(Self.normalizedURLString(article.rawThumbnailLink)) ?? usableProvidedURL(Self.normalizedURLString(article.rawImageLink)) ?? usableProvidedURL(Self.firstSignificantImageAttachmentURL(article)) + usableProvidedURL(Self.thumbnailLink(article)) ?? usableProvidedURL(Self.normalizedURLString(article.rawImageLink)) ?? usableProvidedURL(Self.firstSignificantImageAttachmentURL(article)) case .large: usableProvidedURL(Self.normalizedURLString(article.rawImageLink)) ?? usableProvidedURL(Self.firstSignificantImageAttachmentURL(article)) } @@ -252,6 +252,14 @@ private extension ArticleThumbnailFinder { return thumbnailURLs } + /// Nil when the article’s image is a placeholder, since a sync service’s thumbnail is its crop of that image. + static func thumbnailLink(_ article: Article) -> String? { + if let rawImageLink = article.rawImageLink, SignificantImageFilter.isPlaceholder(urlString: rawImageLink) { + return nil + } + return normalizedURLString(article.rawThumbnailLink) + } + static func firstSignificantImageAttachmentURL(_ article: Article) -> String? { guard let attachments = article.attachments else { return nil diff --git a/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift b/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift index 2b9fc79ba..d2230de93 100644 --- a/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift +++ b/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift @@ -24,6 +24,14 @@ public enum SignificantImageFilter { hasSignificantDimensions(width: width, height: height) && !isBlockedURL(urlString) && !hasDecorativeClass(htmlClass) && !isSharingLink(enclosingLinkURLString) } + /// A site’s stand-in for an article with no image of its own. + public static func isPlaceholder(urlString: String) -> Bool { + guard let url = URL(string: urlString), let host = url.host()?.lowercased() else { + return false + } + return matches(host: host, path: url.path().lowercased(), placeholderImagePrefixes) + } + public static func hasSignificantDimensions(width: Int?, height: Int?) -> Bool { if let width, width < minimumDimension { return false @@ -67,6 +75,11 @@ private extension SignificantImageFilter { (host: "stats.wordpress.com", pathPrefix: "/") ] + /// Hosts include their subdomains. Path prefixes are lowercase. + static let placeholderImagePrefixes: [HostAndPathPrefix] = [ + (host: "boston.com", pathPrefix: "/wp-content/themes/bdc-2020/assets/images/feed-placeholder.png") + ] + /// Share endpoints. Hosts include their subdomains. Path prefixes are lowercase. static let sharingLinkPrefixes: [HostAndPathPrefix] = [ (host: "addtoany.com", pathPrefix: "/"), @@ -111,7 +124,7 @@ private extension SignificantImageFilter { if !photoFileExtensions.contains(url.pathExtension.lowercased()), url.pathComponents.contains(where: { blockedPathComponents.contains($0.lowercased()) }) { return true } - if matches(host: host, path: url.path().lowercased(), blockedImagePrefixes) { + if matches(host: host, path: url.path().lowercased(), blockedImagePrefixes) || isPlaceholder(urlString: urlString) { return true } return MediaRSS.isGravatar(url) diff --git a/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift b/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift index 4be7d6d4c..d04c14277 100644 --- a/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift @@ -163,6 +163,7 @@ import RSParser #expect(!SignificantImageFilter.isSignificant(urlString: "https://example.com/logo.svg", width: nil, height: nil)) #expect(!SignificantImageFilter.isSignificant(urlString: "https://s0.wp.com/i/blank.jpg", width: nil, height: nil)) #expect(!SignificantImageFilter.isSignificant(urlString: "https://pixel.wp.com/b.gif?v=1", width: nil, height: nil)) + #expect(!SignificantImageFilter.isSignificant(urlString: "https://www.boston.com/wp-content/themes/bdc-2020/assets/images/feed-placeholder.png", width: nil, height: nil)) #expect(!SignificantImageFilter.isSignificant(urlString: "ftp://example.com/a.jpg", width: nil, height: nil)) #expect(!SignificantImageFilter.isSignificant(urlString: "https://example.com/banner.jpg", width: 1200, height: 150)) #expect(!SignificantImageFilter.isSignificant(urlString: "https://example.com/images/spacer.gif", width: nil, height: nil)) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 3247b9887..0b96daaa7 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -288,26 +288,30 @@ private extension ArticleRenderer { // Templates without [[primary_media]], and short untitled posts, get the article image in the enclosures. // The thumbnail is used only for [[primary_media]]. let bodyImageIdentities = Self.bodyImageIdentities(body, baseURL: baseURL) - var attachments = article.attachments ?? [] + var attachments = (article.attachments ?? []).filter { !SignificantImageFilter.isPlaceholder(urlString: $0.url) } + // A sync service’s thumbnail is its crop of the article image, so it’s a placeholder too. + let hasPlaceholderImage = SignificantImageFilter.isPlaceholder(urlString: article.imageLink ?? "") + let imageLink = hasPlaceholderImage ? nil : article.imageLink + let thumbnailLink = hasPlaceholderImage ? nil : article.thumbnailLink // Feedbin’s image is also the timeline thumbnail, so it’s shown instead of the feed’s image enclosure. - if article.account?.type == .feedbin, let imageLink = article.imageLink, !imageLink.isEmpty { + if article.account?.type == .feedbin, let imageLink, !imageLink.isEmpty { attachments.removeAll { $0.displayMedium == .image } } var primaryMediaHTML = "" var primaryMediaURLs = Set() let hasPrimaryMedia = template().contains(Self.primaryMediaMacro) let showsPrimaryImage = hasPrimaryMedia && !Self.isShortUntitledPost(title: article.title, body: body) - if hasPrimaryMedia, let primaryMedia = Self.primaryMedia(imageLink: article.imageLink, thumbnailLink: article.thumbnailLink, attachments: attachments, articleTitle: article.title, body: body, bodyImageIdentities: bodyImageIdentities, includesImage: showsPrimaryImage) { + if hasPrimaryMedia, let primaryMedia = Self.primaryMedia(imageLink: imageLink, thumbnailLink: thumbnailLink, attachments: attachments, articleTitle: article.title, body: body, bodyImageIdentities: bodyImageIdentities, includesImage: showsPrimaryImage) { primaryMediaHTML = primaryMedia.html primaryMediaURLs = primaryMedia.attachmentURLs attachments.removeAll { primaryMediaURLs.contains($0.url) } } - if !showsPrimaryImage, let primaryImage = Self.primaryImage(imageLink: article.imageLink, thumbnailLink: nil, attachments: attachments, body: body, bodyImageIdentities: bodyImageIdentities), !primaryMediaURLs.contains(primaryImage.url), !attachments.contains(primaryImage) { + if !showsPrimaryImage, let primaryImage = Self.primaryImage(imageLink: imageLink, thumbnailLink: nil, attachments: attachments, body: body, bodyImageIdentities: bodyImageIdentities), !primaryMediaURLs.contains(primaryImage.url), !attachments.contains(primaryImage) { attachments.insert(primaryImage, at: 0) } // Templates without [[enclosures]] get them at the end of the body. - var enclosures = Self.enclosuresHTML(attachments: attachments, body: body, bodyImageIdentities: bodyImageIdentities, posterURL: article.imageLink ?? article.thumbnailLink) + var enclosures = Self.enclosuresHTML(attachments: attachments, body: body, bodyImageIdentities: bodyImageIdentities, posterURL: imageLink ?? thumbnailLink) var body = body if routesThumbnailImages, let thumbnailMode = AppDefaults.timelineThumbnailsDisplay.thumbnailMode, let thumbnailURL = ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) { body = Self.routingThumbnailImages(body, thumbnailURL: thumbnailURL, baseURL: baseURL)