Merge branch 'main' into tiqoe

This commit is contained in:
Justin Reeves authored and GitHub committed 2026-12-03 01:56:54 -06:00
commit fe5a6aa2dd
12 files changed
+136 -55

No files matched your search

+1 -1
View File
@@ -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))
+1 -1
View File
@@ -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
-22
View File
@@ -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
}
}
@@ -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
@@ -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)
@@ -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))
@@ -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.
@@ -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()
}
}
@@ -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<String>) -> 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)
}
+23 -6
View File
@@ -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 = {
@@ -263,7 +267,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 {
@@ -279,22 +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, !imageLink.isEmpty {
attachments.removeAll { $0.displayMedium == .image }
}
var primaryMediaHTML = ""
var primaryMediaURLs = Set<String>()
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)
@@ -106,6 +106,34 @@ 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)
}
// 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)
+6
View File
@@ -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;
}
@@ -50,6 +50,26 @@ import Articles
#expect(ArticleRenderer.primaryImageHTML(primaryImage, articleTitle: nil) == "<div class=\"nnw-primary-image\"><img src=\"\(imageURL)\" alt=\"Great blue heron at Green Lake\" title=\"Great blue heron at Green Lake\" width=\"1200\" height=\"800\"><div class=\"nnw-primary-image-caption\">Great blue heron at Green Lake</div></div>")
}
// 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 = "<p>Federal officials are proposing new requirements for school lunches as part of an effort to combat obesity and other chronic health conditions</p>"
#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 = "<p>All 13 measles cases in Vermont are in Orleans County, which is located in the state’s northeast corner.</p>"
#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"