From bdd858f5099e2e8afb5164b60bd8ce38e92c2449 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 19 Jan 2025 21:15:26 -0800 Subject: [PATCH] Centralize logic for when to use the nnw feed icon. --- Shared/Favicons/FaviconDownloader.swift | 2 +- Shared/Images/FeedIconDownloader.swift | 4 +-- Shared/Images/ImageUtilities.swift | 34 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 Shared/Images/ImageUtilities.swift diff --git a/Shared/Favicons/FaviconDownloader.swift b/Shared/Favicons/FaviconDownloader.swift index e5ab2133a..627c946f5 100644 --- a/Shared/Favicons/FaviconDownloader.swift +++ b/Shared/Favicons/FaviconDownloader.swift @@ -123,7 +123,7 @@ final class FaviconDownloader { let url = homePageURL.normalizedURL if let url = URL(string: homePageURL) { - if url.host == "nnw.ranchero.com" || url.host == "netnewswire.blog" { + if ImageUtilities.shouldUseNNWFeedIcon(with: url) { return IconImage.nnwFeedIcon } } diff --git a/Shared/Images/FeedIconDownloader.swift b/Shared/Images/FeedIconDownloader.swift index bbbb9ecdb..fe49b7757 100644 --- a/Shared/Images/FeedIconDownloader.swift +++ b/Shared/Images/FeedIconDownloader.swift @@ -50,8 +50,8 @@ public final class FeedIconDownloader { if let cachedImage = cache[feed] { return cachedImage } - - if let homePageURLString = feed.homePageURL, let homePageURL = URL(string: homePageURLString), (homePageURL.host == "nnw.ranchero.com" || homePageURL.host == "netnewswire.blog") { + + if let feedURL = URL(string: feed.url), ImageUtilities.shouldUseNNWFeedIcon(with: feedURL) { return IconImage.nnwFeedIcon } diff --git a/Shared/Images/ImageUtilities.swift b/Shared/Images/ImageUtilities.swift new file mode 100644 index 000000000..ecd3265d0 --- /dev/null +++ b/Shared/Images/ImageUtilities.swift @@ -0,0 +1,34 @@ +// +// ImageUtilities.swift +// NetNewsWire +// +// Created by Brent Simmons on 1/19/25. +// Copyright © 2025 Ranchero Software. All rights reserved. +// + +import Foundation + +struct ImageUtilities { + + static func shouldUseNNWFeedIcon(with feedURL: URL) -> Bool { + + guard let host = feedURL.host() else { + return false + } + + if host == "nnw.ranchero.com" || host == "netnewswire.blog" { + return true + } + if host != "ranchero.com" { + return false + } + + let absoluteString = feedURL.absoluteString + if absoluteString == "https://ranchero.com/downloads/netnewswire-beta.xml" || absoluteString == "https://ranchero.com/downloads/netnewswire-release.xml" { + return true + } + + return false + } +} +