Prefer Apple touch icons to other feed icons.

This commit is contained in:
Brent Simmons 2017-11-26 20:40:07 -08:00
parent 4e50529b16
commit 6c36107320
4 changed files with 41 additions and 5 deletions

View File

@ -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 = "<group>"; };
8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLMetadataDownloader.swift; sourceTree = "<group>"; };
8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturedImageDownloader.swift; sourceTree = "<group>"; };
842611A11FCB769D0086A189 /* RSHTMLData+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RSHTMLData+Extension.swift"; sourceTree = "<group>"; };
842611A11FCB769D0086A189 /* RSHTMLMetadata+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RSHTMLMetadata+Extension.swift"; sourceTree = "<group>"; };
842E45CD1ED8C308000A8B52 /* AppNotifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppNotifications.swift; path = Evergreen/AppNotifications.swift; sourceTree = "<group>"; };
842E45DC1ED8C54B000A8B52 /* Browser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Browser.swift; path = Evergreen/Browser.swift; sourceTree = "<group>"; };
842E45E21ED8C681000A8B52 /* KeyboardDelegateProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardDelegateProtocol.swift; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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 theyre large enough to use here.
if let appleTouchIcon = largestAppleTouchIcon() {
return appleTouchIcon
}
if let openGraphImageURL = largestOpenGraphImageURL() {
return openGraphImageURL
}

View File

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

View File

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