Show favicon in detail view when available and when there’s no user avatar or feed icon.
This commit is contained in:
parent
599b42b9df
commit
d2d7369d6a
@ -19,6 +19,7 @@ class ArticleRenderer {
|
|||||||
|
|
||||||
let article: Article
|
let article: Article
|
||||||
let articleStyle: ArticleStyle
|
let articleStyle: ArticleStyle
|
||||||
|
static var faviconImgTagCache = [Feed: String]()
|
||||||
|
|
||||||
lazy var longDateFormatter: DateFormatter = {
|
lazy var longDateFormatter: DateFormatter = {
|
||||||
let dateFormatter = DateFormatter()
|
let dateFormatter = DateFormatter()
|
||||||
@ -169,21 +170,11 @@ class ArticleRenderer {
|
|||||||
d["newsitem_description"] = body
|
d["newsitem_description"] = body
|
||||||
|
|
||||||
d["avatars"] = ""
|
d["avatars"] = ""
|
||||||
|
var didAddAvatar = false
|
||||||
if let avatar = avatarToUse() {
|
if let avatar = avatarToUse() {
|
||||||
let avatarHTML = avatar.html(dimension: 64)
|
let avatarHTML = avatar.html(dimension: 64)
|
||||||
d["avatars"] = avatarHTML
|
d["avatars"] = avatarHTML
|
||||||
// var ix = 0
|
didAddAvatar = true
|
||||||
// let ct = avatars.count
|
|
||||||
// for avatar in avatars {
|
|
||||||
// avatarHTML += avatar.html(dimension: 64)
|
|
||||||
// if ix < ct - 1 {
|
|
||||||
// avatarHTML += " "
|
|
||||||
// }
|
|
||||||
// ix += 1
|
|
||||||
// }
|
|
||||||
// if !avatarHTML.isEmpty {
|
|
||||||
// d["avatars"] = avatarHTML
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var feedLink = ""
|
var feedLink = ""
|
||||||
@ -196,6 +187,13 @@ class ArticleRenderer {
|
|||||||
d["feedlink"] = feedLink
|
d["feedlink"] = feedLink
|
||||||
d["feedlink_withfavicon"] = feedLink
|
d["feedlink_withfavicon"] = feedLink
|
||||||
|
|
||||||
|
d["favicon"] = ""
|
||||||
|
if !didAddAvatar, let feed = article.feed {
|
||||||
|
if let favicon = faviconImgTag(forFeed: feed) {
|
||||||
|
d["favicon"] = favicon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let longDate = longDateFormatter.string(from: article.logicalDatePublished)
|
let longDate = longDateFormatter.string(from: article.logicalDatePublished)
|
||||||
let mediumDate = mediumDateFormatter.string(from: article.logicalDatePublished)
|
let mediumDate = mediumDateFormatter.string(from: article.logicalDatePublished)
|
||||||
let shortDate = shortDateFormatter.string(from: article.logicalDatePublished)
|
let shortDate = shortDateFormatter.string(from: article.logicalDatePublished)
|
||||||
@ -230,6 +228,30 @@ class ArticleRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func faviconImgTag(forFeed feed: Feed) -> String? {
|
||||||
|
|
||||||
|
if let cachedImgTag = ArticleRenderer.faviconImgTagCache[feed] {
|
||||||
|
return cachedImgTag
|
||||||
|
}
|
||||||
|
|
||||||
|
if let favicon = appDelegate.faviconDownloader.favicon(for: feed) {
|
||||||
|
if let s = base64String(forImage: favicon) {
|
||||||
|
let imgTag = "<img src=\"data:image/tiff;base64, " + s + "\" height=16 width=16 />"
|
||||||
|
ArticleRenderer.faviconImgTagCache[feed] = imgTag
|
||||||
|
return imgTag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func base64String(forImage image: NSImage) -> String? {
|
||||||
|
|
||||||
|
|
||||||
|
let d = image.tiffRepresentation
|
||||||
|
return d?.base64EncodedString()
|
||||||
|
}
|
||||||
|
|
||||||
private func singleArticleSpecifiedAuthor() -> Author? {
|
private func singleArticleSpecifiedAuthor() -> Author? {
|
||||||
|
|
||||||
// The author of this article, if just one.
|
// The author of this article, if just one.
|
||||||
|
@ -68,7 +68,7 @@ a:hover {
|
|||||||
.headerTable {
|
.headerTable {
|
||||||
widtdh: 100%;
|
widtdh: 100%;
|
||||||
}
|
}
|
||||||
.headerContainer img {
|
.avatar img {
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
<div class="headerContainer">
|
<div class="headerContainer">
|
||||||
<table cellpadding=0 cellspacing=0 border=0 class="headerTable">
|
<table cellpadding=0 cellspacing=0 border=0 class="headerTable">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="header leftAlign">[[avatars]]</td>
|
<td class="header leftAlign avatar">[[avatars]]</td>
|
||||||
<td class="header leftAlign"><b>[[feedlink]]</b><br />[[byline]]</td>
|
<td class="header leftAlign">[[favicon]] <b>[[feedlink]]</b><br />[[byline]]</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user