From b3ecf9cdbaf3b19b6285f532db01578656cd3cde Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 13 Dec 2017 19:45:12 -0800 Subject: [PATCH] Base the homePageURL for a feed from its feed URL when looking for its favicon. When necessary only. --- Evergreen/Favicons/FaviconDownloader.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Evergreen/Favicons/FaviconDownloader.swift b/Evergreen/Favicons/FaviconDownloader.swift index 45e7a558d..3d8ca5f0c 100644 --- a/Evergreen/Favicons/FaviconDownloader.swift +++ b/Evergreen/Favicons/FaviconDownloader.swift @@ -47,10 +47,18 @@ final class FaviconDownloader { return favicon(with: faviconURL) } - guard let homePageURL = feed.homePageURL else { - return nil + var homePageURL = feed.homePageURL + if homePageURL == nil { + // Base homePageURL off feedURL if needed. Won’t always be accurate, but is good enough. + if let feedURL = URL(string: feed.url), let scheme = feedURL.scheme, let host = feedURL.host { + homePageURL = scheme + "://" + host + "/" + } } - return favicon(withHomePageURL: homePageURL) + if let homePageURL = homePageURL { + return favicon(withHomePageURL: homePageURL) + } + + return nil } func favicon(with faviconURL: String) -> NSImage? {