mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-13 13:01:03 +00:00
fix getFirstImageOf(..)
This commit is contained in:
parent
abda51ec58
commit
d63436b1d9
2 changed files with 13 additions and 4 deletions
|
@ -63,7 +63,7 @@ extension ParsedItem {
|
|||
(url: imageURL, size: image.size)
|
||||
} else if
|
||||
let contentHTML = self.contentHTML,
|
||||
let imageURL = RSSTools.getFirstImageOf(html: contentHTML),
|
||||
let imageURL = RSSTools.getFirstImageOf(html: contentHTML, baseURL: self.getRSSURL()),
|
||||
let imageData = try? Data(contentsOf: imageURL),
|
||||
let image = UIImage(data: imageData)
|
||||
{
|
||||
|
|
|
@ -103,9 +103,18 @@ public enum RSSTools {
|
|||
return NonEmptyString(String(match.1))
|
||||
}
|
||||
|
||||
public static func getFirstImageOf(html: String) -> URL? {
|
||||
guard let match = html.firstMatch(of: /<img[\s\S]+?src="(.+?)"/) else { return nil }
|
||||
return URL(string: String(match.1))
|
||||
public static func getFirstImageOf(html: String, baseURL: URL?) -> URL? {
|
||||
guard let match = html.firstMatch(of: /<img[\s\S]+?src="(.+?)"/),
|
||||
let url = URL(string: String(match.1))
|
||||
else { return nil }
|
||||
|
||||
return if url.host != nil {
|
||||
url
|
||||
} else if let host = baseURL?.host() {
|
||||
URL(string: "https://\(host)\(url.absoluteString)")
|
||||
} else {
|
||||
nil
|
||||
}
|
||||
}
|
||||
|
||||
public static func getFeedData(from feedURL: URL) async -> RSSFeed.SendableData? {
|
||||
|
|
Loading…
Reference in a new issue