diff --git a/Evergreen/MainWindow/Detail/ArticleRenderer.swift b/Evergreen/MainWindow/Detail/ArticleRenderer.swift
index 3e082485b..3bfa8bee8 100644
--- a/Evergreen/MainWindow/Detail/ArticleRenderer.swift
+++ b/Evergreen/MainWindow/Detail/ArticleRenderer.swift
@@ -133,6 +133,11 @@ class ArticleRenderer {
private func linkWithText(_ text: String, _ href: String) -> String {
+ return ArticleRenderer.linkWithText(text, href)
+ }
+
+ private static func linkWithText(_ text: String, _ href: String) -> String {
+
return "\(text)"
}
@@ -161,22 +166,29 @@ class ArticleRenderer {
d["article_description"] = body
d["newsitem_description"] = body
+ d["avatars"] = ""
+ if let avatars = avatarsToShow() {
+ var avatarHTML = ""
+ var ix = 0
+ 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 = ""
if let feedTitle = article.feed?.nameForDisplay {
feedLink = feedTitle
if let feedURL = article.feed?.homePageURL {
feedLink = linkWithTextAndClass(feedTitle, feedURL, "feedLink")
}
- if let feedIcon = article.feed?.iconURL {
- let feedIconImage = ""
- if let feedURL = article.feed?.homePageURL {
- let feedIconImageLink = linkWithText(feedIconImage, feedURL)
- feedLink = feedIconImageLink + " " + feedLink
- }
- else {
- feedLink = feedIconImage + " " + feedLink
- }
- }
}
d["feedlink"] = feedLink
d["feedlink_withfavicon"] = feedLink
@@ -191,27 +203,107 @@ class ArticleRenderer {
d["date_short"] = shortDate
d["byline"] = byline()
- d["author_avatar"] = authorAvatar()
+// d["author_avatar"] = authorAvatar()
return d
}
- private func authorAvatar() -> String {
+ struct Avatar {
+ let imageURL: String
+ let url: String?
- guard let authors = article.authors, authors.count == 1, let author = authors.first else {
- return ""
- }
- guard let avatarURL = author.avatarURL else {
- return ""
- }
+ func html(dimension: Int) -> String {
- var imageTag = "
"
- if let authorURL = author.url {
- imageTag = linkWithText(imageTag, authorURL)
+ let imageTag = "
\(imageTag)"
}
+ private func singleArticleSpecifiedAuthor() -> Author? {
+
+ // The author of this article, if just one.
+
+ if let authors = article.authors, authors.count == 1 {
+ return authors.first!
+ }
+ return nil
+ }
+
+ private func singleFeedSpecifiedAuthor() -> Author? {
+
+ if let authors = article.feed?.authors, authors.count == 1 {
+ return authors.first!
+ }
+ return nil
+ }
+
+ private func feedAvatar() -> Avatar? {
+
+ guard let feedIconURL = article.feed?.iconURL else {
+ return nil
+ }
+ return Avatar(imageURL: feedIconURL, url: article.feed?.homePageURL ?? article.feed?.url)
+ }
+
+ private func authorAvatar() -> Avatar? {
+
+ if let author = singleArticleSpecifiedAuthor(), let imageURL = author.avatarURL {
+ return Avatar(imageURL: imageURL, url: author.url)
+ }
+ if let author = singleFeedSpecifiedAuthor(), let imageURL = author.avatarURL {
+ return Avatar(imageURL: imageURL, url: author.url)
+ }
+ return nil
+ }
+
+ private func avatarsToShow() -> [Avatar]? {
+
+ var avatars = [Avatar]()
+ if let avatar = feedAvatar() {
+ avatars.append(avatar)
+ }
+ if let avatar = authorAvatar() {
+ avatars.append(avatar)
+ }
+ return avatars.isEmpty ? nil : avatars
+ }
+
+ private func avatarToUse() -> Avatar? {
+
+ // Use author if article specifies an author, otherwise use feed icon.
+ // If no feed icon, use feed-specified author.
+
+ if let author = singleArticleSpecifiedAuthor(), let imageURL = author.avatarURL {
+ return Avatar(imageURL: imageURL, url: author.url)
+ }
+ if let feedIconURL = article.feed?.iconURL {
+ return Avatar(imageURL: feedIconURL, url: article.feed?.homePageURL ?? article.feed?.url)
+ }
+ if let author = singleFeedSpecifiedAuthor(), let imageURL = author.avatarURL {
+ return Avatar(imageURL: imageURL, url: author.url)
+ }
+ return nil
+ }
+
+// private func authorAvatar() -> String {
+//
+// guard let authors = article.authors, authors.count == 1, let author = authors.first else {
+// return ""
+// }
+// guard let avatarURL = author.avatarURL else {
+// return ""
+// }
+//
+// var imageTag = "
"
+// if let authorURL = author.url {
+// imageTag = linkWithText(imageTag, authorURL)
+// }
+// return "
[[avatars]]
+[[feedlink]] • [[byline]] • [[date_short]]