mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 14:33:04 +01:00
Use feed icon’s gathered from HTML metadata.
This commit is contained in:
parent
d2d7369d6a
commit
5dd20264bf
@ -20,6 +20,7 @@ class ArticleRenderer {
|
||||
let article: Article
|
||||
let articleStyle: ArticleStyle
|
||||
static var faviconImgTagCache = [Feed: String]()
|
||||
static var feedIconImgTagCache = [Feed: String]()
|
||||
|
||||
lazy var longDateFormatter: DateFormatter = {
|
||||
let dateFormatter = DateFormatter()
|
||||
@ -171,8 +172,7 @@ class ArticleRenderer {
|
||||
|
||||
d["avatars"] = ""
|
||||
var didAddAvatar = false
|
||||
if let avatar = avatarToUse() {
|
||||
let avatarHTML = avatar.html(dimension: 64)
|
||||
if let avatarHTML = avatarImgTag() {
|
||||
d["avatars"] = avatarHTML
|
||||
didAddAvatar = true
|
||||
}
|
||||
@ -245,6 +245,23 @@ class ArticleRenderer {
|
||||
return nil
|
||||
}
|
||||
|
||||
private func feedIconImgTag(forFeed feed: Feed) -> String? {
|
||||
|
||||
if let cachedImgTag = ArticleRenderer.feedIconImgTagCache[feed] {
|
||||
return cachedImgTag
|
||||
}
|
||||
|
||||
if let icon = appDelegate.feedIconDownloader.icon(for: feed) {
|
||||
if let s = base64String(forImage: icon) {
|
||||
let imgTag = "<img src=\"data:image/tiff;base64, " + s + "\" height=48 width=48 />"
|
||||
ArticleRenderer.feedIconImgTagCache[feed] = imgTag
|
||||
return imgTag
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
private func base64String(forImage image: NSImage) -> String? {
|
||||
|
||||
|
||||
@ -318,6 +335,25 @@ class ArticleRenderer {
|
||||
return nil
|
||||
}
|
||||
|
||||
private let avatarDimension = 48
|
||||
|
||||
private func avatarImgTag() -> String? {
|
||||
|
||||
if let author = singleArticleSpecifiedAuthor(), let imageURL = author.avatarURL {
|
||||
return Avatar(imageURL: imageURL, url: author.url).html(dimension: avatarDimension)
|
||||
}
|
||||
if let feed = article.feed, let imgTag = feedIconImgTag(forFeed: feed) {
|
||||
return imgTag
|
||||
}
|
||||
if let feedIconURL = article.feed?.iconURL {
|
||||
return Avatar(imageURL: feedIconURL, url: article.feed?.homePageURL ?? article.feed?.url).html(dimension: avatarDimension)
|
||||
}
|
||||
if let author = singleFeedSpecifiedAuthor(), let imageURL = author.avatarURL {
|
||||
return Avatar(imageURL: imageURL, url: author.url).html(dimension: avatarDimension)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// private func authorAvatar() -> String {
|
||||
//
|
||||
// guard let authors = article.authors, authors.count == 1, let author = authors.first else {
|
||||
|
Loading…
Reference in New Issue
Block a user