Skip to content

Commit

Permalink
Unify avatar class generation
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Jan 14, 2022
1 parent cc0e4b1 commit 888e965
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/views/general.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
let opensearchUrl = getUrlPrefix(cfg) & "/opensearch"

buildHtml(head):
link(rel="stylesheet", type="text/css", href="/css/style.css?v=9")
link(rel="stylesheet", type="text/css", href="/css/style.css?v=10")
link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=2")

if theme.len > 0:
Expand Down
6 changes: 6 additions & 0 deletions src/views/renderutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ proc getTabClass*(query: Query; tab: QueryKind): string =
result = "tab-item"
if query.kind == tab:
result &= " active"

proc getAvatarClass*(prefs: Prefs): string =
if prefs.squareAvatars:
"avatar"
else:
"avatar round"
2 changes: 1 addition & 1 deletion src/views/timeline.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ proc renderUser(user: Profile; prefs: Prefs): VNode =
tdiv(class="tweet-body profile-result"):
tdiv(class="tweet-header"):
a(class="tweet-avatar", href=("/" & user.username)):
genImg(user.getUserPic("_bigger"), class="avatar")
genImg(user.getUserPic("_bigger"), class=prefs.getAvatarClass)

tdiv(class="tweet-name-row"):
tdiv(class="fullname-and-username"):
Expand Down
16 changes: 7 additions & 9 deletions src/views/tweet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ proc getSmallPic(url: string): string =
result &= ":small"
result = getPicUrl(result)

proc renderMiniAvatar(profile: Profile): VNode =
proc renderMiniAvatar(profile: Profile; prefs: Prefs): VNode =
let url = getPicUrl(profile.getUserPic("_mini"))
buildHtml():
img(class="avatar mini", src=url)
img(class=(prefs.getAvatarClass & " mini"), src=url)

proc renderHeader(tweet: Tweet; retweet: string; prefs: Prefs): VNode =
buildHtml(tdiv):
Expand All @@ -31,9 +31,7 @@ proc renderHeader(tweet: Tweet; retweet: string; prefs: Prefs): VNode =
var size = "_bigger"
if not prefs.autoplayGifs and tweet.profile.userPic.endsWith("gif"):
size = "_400x400"

let round = if prefs.squareAvatars: "" else: " round"
genImg(tweet.profile.getUserPic(size), class=(&"avatar{round}"))
genImg(tweet.profile.getUserPic(size), class=prefs.getAvatarClass)

tdiv(class="tweet-name-row"):
tdiv(class="fullname-and-username"):
Expand Down Expand Up @@ -203,9 +201,9 @@ proc renderReply(tweet: Tweet): VNode =
if i > 0: text " "
a(href=("/" & u)): text "@" & u

proc renderAttribution(profile: Profile): VNode =
proc renderAttribution(profile: Profile; prefs: Prefs): VNode =
buildHtml(a(class="attribution", href=("/" & profile.username))):
renderMiniAvatar(profile)
renderMiniAvatar(profile, prefs)
strong: text profile.fullname
if profile.verified:
icon "ok", class="verified-icon", title="Verified account"
Expand Down Expand Up @@ -244,7 +242,7 @@ proc renderQuote(quote: Tweet; prefs: Prefs; path: string): VNode =

tdiv(class="tweet-name-row"):
tdiv(class="fullname-and-username"):
renderMiniAvatar(quote.profile)
renderMiniAvatar(quote.profile, prefs)
linkUser(quote.profile, class="fullname")
linkUser(quote.profile, class="username")

Expand Down Expand Up @@ -323,7 +321,7 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0;
verbatim replaceUrls(tweet.text, prefs) & renderLocation(tweet)

if tweet.attribution.isSome:
renderAttribution(tweet.attribution.get())
renderAttribution(tweet.attribution.get(), prefs)

if tweet.card.isSome:
renderCard(tweet.card.get(), prefs, path)
Expand Down

0 comments on commit 888e965

Please sign in to comment.