Switch to new Parser.

This commit is contained in:
Brent Simmons
2024-11-15 22:59:51 -08:00
parent c3f063ae4a
commit 85d1a8fe7a
79 changed files with 187 additions and 219 deletions

View File

@@ -7,65 +7,32 @@
//
import Foundation
import RSParser
import Parser
extension RSHTMLMetadata {
func largestOpenGraphImageURL() -> String? {
let openGraphImages = openGraphProperties.images
guard !openGraphImages.isEmpty else {
return nil
}
var bestImage: RSHTMLOpenGraphImage? = nil
for image in openGraphImages {
if image.width / image.height > 2 {
continue
}
if bestImage == nil {
bestImage = image
continue
}
if image.height > bestImage!.height && image.width > bestImage!.width {
bestImage = image
}
}
guard let url = bestImage?.secureURL ?? bestImage?.url else {
return nil
}
// Bad ones we should ignore.
let badURLs = Set(["https://s0.wp.com/i/blank.jpg"])
guard !badURLs.contains(url) else {
return nil
}
return url
}
extension HTMLMetadata {
func largestAppleTouchIcon() -> String? {
let icons = appleTouchIcons
guard !icons.isEmpty else {
guard let icons = appleTouchIcons, !icons.isEmpty else {
return nil
}
var bestImage: RSHTMLMetadataAppleTouchIcon? = nil
var bestImage: HTMLMetadataAppleTouchIcon? = nil
for image in icons {
if image.size.width / image.size.height > 2 {
continue
if let size = image.size {
if size.width / size.height > 2 {
continue
}
}
if bestImage == nil {
bestImage = image
continue
}
if image.size.height > bestImage!.size.height && image.size.width > bestImage!.size.width {
bestImage = image;
if let size = image.size, let bestImageSize = bestImage!.size {
if size.height > bestImageSize.height && size.width > bestImageSize.width {
bestImage = image;
}
}
}
@@ -80,19 +47,10 @@ extension RSHTMLMetadata {
return appleTouchIcon
}
if let openGraphImageURL = largestOpenGraphImageURL() {
if let openGraphImageURL = openGraphProperties?.image?.url {
return openGraphImageURL
}
return twitterProperties.imageURL
}
func bestFeaturedImageURL() -> String? {
if let openGraphImageURL = largestOpenGraphImageURL() {
return openGraphImageURL
}
return twitterProperties.imageURL
return twitterProperties?.imageURL
}
}