This commit is contained in:
Brent Simmons 2018-02-16 21:02:41 -08:00
commit 2b4bb520ed
1 changed files with 30 additions and 1 deletions

View File

@ -134,7 +134,7 @@ private extension JSONFeedParser {
let url = itemDictionary[Key.url] as? String let url = itemDictionary[Key.url] as? String
let externalURL = itemDictionary[Key.externalURL] as? String let externalURL = itemDictionary[Key.externalURL] as? String
let title = itemDictionary[Key.title] as? String let title = parseTitle(itemDictionary, feedURL)
let summary = itemDictionary[Key.summary] as? String let summary = itemDictionary[Key.summary] as? String
let imageURL = itemDictionary[Key.image] as? String let imageURL = itemDictionary[Key.image] as? String
let bannerImageURL = itemDictionary[Key.bannerImage] as? String let bannerImageURL = itemDictionary[Key.bannerImage] as? String
@ -152,6 +152,35 @@ private extension JSONFeedParser {
return ParsedItem(syncServiceID: nil, uniqueID: uniqueID, feedURL: feedURL, url: url, externalURL: externalURL, title: title, contentHTML: decodedContentHTML, contentText: contentText, summary: summary, imageURL: imageURL, bannerImageURL: bannerImageURL, datePublished: datePublished, dateModified: dateModified, authors: authors, tags: tags, attachments: attachments) return ParsedItem(syncServiceID: nil, uniqueID: uniqueID, feedURL: feedURL, url: url, externalURL: externalURL, title: title, contentHTML: decodedContentHTML, contentText: contentText, summary: summary, imageURL: imageURL, bannerImageURL: bannerImageURL, datePublished: datePublished, dateModified: dateModified, authors: authors, tags: tags, attachments: attachments)
} }
static func parseTitle(_ itemDictionary: JSONDictionary, _ feedURL: String) -> String? {
guard let title = itemDictionary[Key.title] as? String else {
return nil
}
if isSpecialCaseTitleWithEntitiesFeed(feedURL) {
return (title as NSString).rsparser_stringByDecodingHTMLEntities()
}
return title
}
static func isSpecialCaseTitleWithEntitiesFeed(_ feedURL: String) -> Bool {
// As of 16 Feb. 2018, Kottkes and Heers feeds includes HTML entities in the title elements.
// If we find more feeds like this, well add them here. If these feeds get fixed, well remove them.
let lowerFeedURL = feedURL.lowercased()
let matchStrings = ["kottke.org", "pxlnv.com"]
for matchString in matchStrings {
if lowerFeedURL.contains(matchString) {
return true
}
}
return false
}
static func parseUniqueID(_ itemDictionary: JSONDictionary) -> String? { static func parseUniqueID(_ itemDictionary: JSONDictionary) -> String? {
if let uniqueID = itemDictionary[Key.uniqueID] as? String { if let uniqueID = itemDictionary[Key.uniqueID] as? String {