Centralize logic for when to use the nnw feed icon.

This commit is contained in:
Brent Simmons 2025-01-19 21:15:26 -08:00
parent 9e4fb8a7d3
commit bdd858f509
3 changed files with 37 additions and 3 deletions

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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
}
}