mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-25 09:11:13 +01:00
Create FaviconURLFinder, which pulls the favicon URL from the metadata of a web page.
This commit is contained in:
parent
6979b85fb5
commit
91895d4066
@ -106,6 +106,7 @@
|
||||
84F2D53A1FC2308B00998D64 /* UnreadFeed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2D5391FC2308B00998D64 /* UnreadFeed.swift */; };
|
||||
84FB9A2F1EDCD6C4003D53B9 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; };
|
||||
84FB9A301EDCD6C4003D53B9 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
84FF69B11FC3793300DC198E /* FaviconURLFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FF69B01FC3793300DC198E /* FaviconURLFinder.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -488,6 +489,7 @@
|
||||
84F2D5361FC22FCB00998D64 /* TodayFeedDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TodayFeedDelegate.swift; sourceTree = "<group>"; };
|
||||
84F2D5391FC2308B00998D64 /* UnreadFeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnreadFeed.swift; sourceTree = "<group>"; };
|
||||
84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Frameworks/Vendor/Sparkle.framework; sourceTree = SOURCE_ROOT; };
|
||||
84FF69B01FC3793300DC198E /* FaviconURLFinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconURLFinder.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -579,6 +581,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
848F6AE41FC29CFA002D422E /* FaviconDownloader.swift */,
|
||||
84FF69B01FC3793300DC198E /* FaviconURLFinder.swift */,
|
||||
);
|
||||
name = Favicons;
|
||||
path = Evergreen/Favicons;
|
||||
@ -1315,6 +1318,7 @@
|
||||
84DAEE301F86CAFE0058304B /* OPMLImporter.swift in Sources */,
|
||||
849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */,
|
||||
849A97891ED9ECEF007D329B /* ArticleStyle.swift in Sources */,
|
||||
84FF69B11FC3793300DC198E /* FaviconURLFinder.swift in Sources */,
|
||||
849A978A1ED9ECEF007D329B /* ArticleStylesManager.swift in Sources */,
|
||||
849A97791ED9EC04007D329B /* TimelineStringUtilities.swift in Sources */,
|
||||
84F204CE1FAACB660076E152 /* FeedListViewController.swift in Sources */,
|
||||
|
43
Evergreen/Favicons/FaviconURLFinder.swift
Normal file
43
Evergreen/Favicons/FaviconURLFinder.swift
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// FaviconURLFinder.swift
|
||||
// Evergreen
|
||||
//
|
||||
// Created by Brent Simmons on 11/20/17.
|
||||
// Copyright © 2017 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSParser
|
||||
import RSWeb
|
||||
|
||||
// The favicon URL may be specified in the head section of the home page.
|
||||
|
||||
struct FaviconURLFinder {
|
||||
|
||||
static func findFaviconURL(_ homePageURL: String, _ callback: @escaping (String?) -> Void) {
|
||||
|
||||
guard let url = URL(string: homePageURL) else {
|
||||
callback(nil)
|
||||
return
|
||||
}
|
||||
|
||||
download(url) { (data, response, error) in
|
||||
|
||||
guard let data = data, let response = response, response.statusIsOK else {
|
||||
callback(nil)
|
||||
return
|
||||
}
|
||||
|
||||
let link = faviconURL(homePageURL, data)
|
||||
callback(link)
|
||||
}
|
||||
}
|
||||
|
||||
static private func faviconURL(_ url: String, _ webPageData: Data) -> String? {
|
||||
|
||||
let parserData = ParserData(url: url, data: webPageData)
|
||||
let htmlMetadata = RSHTMLMetadataParser.htmlMetadata(with: parserData)
|
||||
return htmlMetadata.faviconLink
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user