diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 104d939fa..9e72606e0 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ 8426118A1FCB67AA0086A189 /* FeedIconDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */; }; 8426119E1FCB6ED40086A189 /* HTMLMetadataDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */; }; 842611A01FCB72600086A189 /* FeaturedImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */; }; - 842611A21FCB769D0086A189 /* RSHTMLData+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611A11FCB769D0086A189 /* RSHTMLData+Extension.swift */; }; + 842611A21FCB769D0086A189 /* RSHTMLMetadata+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611A11FCB769D0086A189 /* RSHTMLMetadata+Extension.swift */; }; 842E45CE1ED8C308000A8B52 /* AppNotifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45CD1ED8C308000A8B52 /* AppNotifications.swift */; }; 842E45DD1ED8C54B000A8B52 /* Browser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45DC1ED8C54B000A8B52 /* Browser.swift */; }; 842E45E31ED8C681000A8B52 /* KeyboardDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45E21ED8C681000A8B52 /* KeyboardDelegateProtocol.swift */; }; @@ -410,7 +410,7 @@ 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedIconDownloader.swift; sourceTree = ""; }; 8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLMetadataDownloader.swift; sourceTree = ""; }; 8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturedImageDownloader.swift; sourceTree = ""; }; - 842611A11FCB769D0086A189 /* RSHTMLData+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RSHTMLData+Extension.swift"; sourceTree = ""; }; + 842611A11FCB769D0086A189 /* RSHTMLMetadata+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RSHTMLMetadata+Extension.swift"; sourceTree = ""; }; 842E45CD1ED8C308000A8B52 /* AppNotifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppNotifications.swift; path = Evergreen/AppNotifications.swift; sourceTree = ""; }; 842E45DC1ED8C54B000A8B52 /* Browser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Browser.swift; path = Evergreen/Browser.swift; sourceTree = ""; }; 842E45E21ED8C681000A8B52 /* KeyboardDelegateProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardDelegateProtocol.swift; sourceTree = ""; }; @@ -586,7 +586,7 @@ 84E850851FCB60CE0072EA88 /* AuthorAvatarDownloader.swift */, 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */, 8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */, - 842611A11FCB769D0086A189 /* RSHTMLData+Extension.swift */, + 842611A11FCB769D0086A189 /* RSHTMLMetadata+Extension.swift */, ); name = Images; path = Evergreen/Images; @@ -1378,7 +1378,7 @@ 849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */, 849A97891ED9ECEF007D329B /* ArticleStyle.swift in Sources */, 84FF69B11FC3793300DC198E /* FaviconURLFinder.swift in Sources */, - 842611A21FCB769D0086A189 /* RSHTMLData+Extension.swift in Sources */, + 842611A21FCB769D0086A189 /* RSHTMLMetadata+Extension.swift in Sources */, 849A978A1ED9ECEF007D329B /* ArticleStylesManager.swift in Sources */, 849A97791ED9EC04007D329B /* TimelineStringUtilities.swift in Sources */, 84F204CE1FAACB660076E152 /* FeedListViewController.swift in Sources */, diff --git a/Evergreen/Images/RSHTMLData+Extension.swift b/Evergreen/Images/RSHTMLMetadata+Extension.swift similarity index 69% rename from Evergreen/Images/RSHTMLData+Extension.swift rename to Evergreen/Images/RSHTMLMetadata+Extension.swift index 5a2df11f1..8d54b84d6 100644 --- a/Evergreen/Images/RSHTMLData+Extension.swift +++ b/Evergreen/Images/RSHTMLMetadata+Extension.swift @@ -1,5 +1,5 @@ // -// RSHTMLData+Extension.swift +// RSHTMLMetadata+Extension.swift // Evergreen // // Created by Brent Simmons on 11/26/17. @@ -42,10 +42,35 @@ extension RSHTMLMetadata { return url } + func largestAppleTouchIcon() -> String? { + + guard let icons = appleTouchIcons, !icons.isEmpty else { + return nil + } + + var bestImage: RSHTMLMetadataAppleTouchIcon? = nil + + for image in icons { + if bestImage == nil { + bestImage = image + continue + } + if image.size.height > bestImage!.size.height && image.size.width > bestImage!.size.width { + bestImage = image; + } + } + + return bestImage?.urlString + } + func bestWebsiteIconURL() -> String? { // TODO: metadata icons — sometimes they’re large enough to use here. + if let appleTouchIcon = largestAppleTouchIcon() { + return appleTouchIcon + } + if let openGraphImageURL = largestOpenGraphImageURL() { return openGraphImageURL } diff --git a/Frameworks/RSParser/HTML/RSHTMLMetadata.h b/Frameworks/RSParser/HTML/RSHTMLMetadata.h index 7ccbc9645..bfcb5e2a5 100755 --- a/Frameworks/RSParser/HTML/RSHTMLMetadata.h +++ b/Frameworks/RSParser/HTML/RSHTMLMetadata.h @@ -36,6 +36,7 @@ @property (nonatomic, readonly) NSString *rel; @property (nonatomic, readonly) NSString *sizes; +@property (nonatomic, readonly) CGSize size; @property (nonatomic, readonly) NSString *urlString; // Absolute. @end diff --git a/Frameworks/RSParser/HTML/RSHTMLMetadata.m b/Frameworks/RSParser/HTML/RSHTMLMetadata.m index b68dbd06e..882144101 100755 --- a/Frameworks/RSParser/HTML/RSHTMLMetadata.m +++ b/Frameworks/RSParser/HTML/RSHTMLMetadata.m @@ -234,6 +234,16 @@ static BOOL typeIsFeedType(NSString *type) { _sizes = [d rsparser_objectForCaseInsensitiveKey:kSizesKey]; _rel = [d rsparser_objectForCaseInsensitiveKey:kRelKey]; + _size = CGSizeZero; + if (_sizes) { + NSArray *components = [_sizes componentsSeparatedByString:@"x"]; + if (components.count == 2) { + CGFloat width = [components[0] floatValue]; + CGFloat height = [components[1] floatValue]; + _size = CGSizeMake(width, height); + } + } + return self; }