adds iconImageUrl to article utils
This commit is contained in:
parent
3254d57189
commit
fe194ec2e5
|
@ -103,6 +103,22 @@ extension Article {
|
|||
return FaviconGenerator.favicon(webFeed)
|
||||
}
|
||||
|
||||
func iconImageUrl(webFeed: WebFeed) -> URL? {
|
||||
if let image = iconImage() {
|
||||
let fm = FileManager.default
|
||||
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
||||
#if os(macOS)
|
||||
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.tiff")
|
||||
#else
|
||||
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.png")
|
||||
#endif
|
||||
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
|
||||
return path
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func byline() -> String {
|
||||
guard let authors = authors ?? webFeed?.authors, !authors.isEmpty else {
|
||||
return ""
|
||||
|
|
|
@ -73,17 +73,8 @@ private extension UserNotificationManager {
|
|||
/// - Returns: A `UNNotifcationAttachment` if an icon is available. Otherwise nil.
|
||||
/// - Warning: In certain scenarios, this will return the `faviconTemplateImage`.
|
||||
func thumbnailAttachment(for article: Article, webFeed: WebFeed) -> UNNotificationAttachment? {
|
||||
if let image = article.iconImage() {
|
||||
let fm = FileManager.default
|
||||
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
||||
#if os(macOS)
|
||||
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.tiff")
|
||||
#else
|
||||
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.png")
|
||||
#endif
|
||||
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
|
||||
|
||||
let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: path, options: nil)
|
||||
if let imageURL = article.iconImageUrl(webFeed: webFeed) {
|
||||
let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: imageURL, options: nil)
|
||||
return thumbnail
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue