2019-06-20 16:16:20 +02:00
|
|
|
#? stdtmpl(subsChar = '$', metaChar = '#')
|
|
|
|
#import xmltree, strutils, times, sequtils, uri
|
|
|
|
#import ../types, ../formatters, ../utils
|
|
|
|
#
|
|
|
|
#proc renderHeading(tweet: Tweet): string =
|
2019-06-20 20:04:18 +02:00
|
|
|
#if tweet.retweetBy.isSome:
|
2019-06-20 16:16:20 +02:00
|
|
|
<div class="retweet">
|
2019-06-20 20:04:18 +02:00
|
|
|
<span>🔄 ${tweet.retweetBy.get()} retweeted</span>
|
2019-06-20 16:16:20 +02:00
|
|
|
</div>
|
|
|
|
#end if
|
|
|
|
#if tweet.pinned:
|
|
|
|
<div class="pinned">
|
|
|
|
<span>📌 Pinned Tweet</span>
|
|
|
|
</div>
|
|
|
|
#end if
|
|
|
|
<div class="media-heading">
|
|
|
|
<div class="heading-name-row">
|
|
|
|
<img class="avatar" src=${tweet.profile.getUserpic("_bigger").getSigUrl("pic")}>
|
|
|
|
<div class="name-and-account-name">
|
|
|
|
${linkUser(tweet.profile, "h4", class="username", username=false)}
|
|
|
|
${linkUser(tweet.profile, "", class="account-name")}
|
|
|
|
</div>
|
|
|
|
<span class="heading-right">
|
|
|
|
<a href="${tweet.link}" class="timeago faint-link">
|
|
|
|
<time title="${tweet.time.format("d/M/yyyy', ' HH:mm:ss")}">${tweet.shortTime}</time>
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
#end proc
|
|
|
|
#
|
2019-06-24 08:07:36 +02:00
|
|
|
#proc renderQuote(quote: Quote): string =
|
|
|
|
#let hasMedia = quote.thumb.isSome()
|
|
|
|
<div class="quote">
|
|
|
|
<div class="quote-container" href="${quote.link}">
|
|
|
|
<a class="quote-link" href="${quote.link}"></a>
|
|
|
|
#if hasMedia:
|
|
|
|
<div class="quote-media-container">
|
|
|
|
<div class="quote-media">
|
|
|
|
<img src=${quote.thumb.get().getSigUrl("pic")}>
|
|
|
|
#if quote.badge.isSome:
|
|
|
|
<div class="quote-badge">${quote.badge.get()}</div>
|
|
|
|
#end if
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
#end if
|
|
|
|
<div class="profile-card-name">
|
|
|
|
${linkUser(quote.profile, "b", class="username", username=false)}
|
|
|
|
${linkUser(quote.profile, "span", class="account-name")}
|
|
|
|
</div>
|
|
|
|
<div class="quote-text">${linkifyText(xmltree.escape(quote.text))}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
#end proc
|
|
|
|
#
|
2019-06-20 16:16:20 +02:00
|
|
|
#proc renderMediaGroup(tweet: Tweet): string =
|
|
|
|
#let groups = if tweet.photos.len > 2: tweet.photos.distribute(2) else: @[tweet.photos]
|
2019-06-24 01:59:32 +02:00
|
|
|
#let display = if groups.len == 1 and groups[0].len == 1: "display: table-caption;" else: ""
|
2019-06-20 16:16:20 +02:00
|
|
|
#var first = true
|
2019-06-24 01:59:32 +02:00
|
|
|
<div class="attachments media-body" style="${display}">
|
2019-06-20 16:16:20 +02:00
|
|
|
#for photos in groups:
|
2019-06-23 22:06:48 +02:00
|
|
|
#let margin = if not first: "margin-top: .25em;" else: ""
|
|
|
|
#let flex = if photos.len > 1 or groups.len > 1: "display: flex;" else: ""
|
|
|
|
<div class="gallery-row cover-fit" style="${margin}">
|
2019-06-20 16:16:20 +02:00
|
|
|
#for photo in photos:
|
|
|
|
<div class="attachment image">
|
|
|
|
##TODO: why doesn't this work?
|
2019-06-23 02:52:07 +02:00
|
|
|
<a href=${getSigUrl(photo & "?name=orig", "pic")} target="_blank" class="image-attachment">
|
2019-06-23 22:06:48 +02:00
|
|
|
<div class="still-image" style="${flex}">
|
|
|
|
<img src=${getSigUrl(photo, "pic")} referrerpolicy="">
|
2019-06-20 16:16:20 +02:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
#end for
|
|
|
|
</div>
|
|
|
|
#first = false
|
|
|
|
#end for
|
|
|
|
</div>
|
|
|
|
#end proc
|
|
|
|
#
|
2019-06-24 05:14:14 +02:00
|
|
|
#proc renderVideo(video: Video): string =
|
2019-06-20 17:20:32 +02:00
|
|
|
<div class="attachments media-body">
|
|
|
|
<div class="gallery-row" style="max-height: unset;">
|
|
|
|
<div class="attachment image">
|
2019-06-24 05:14:14 +02:00
|
|
|
<video poster=${video.thumb.getSigUrl("pic")} autoplay muted loop></video>
|
2019-06-20 17:20:32 +02:00
|
|
|
<div class="video-overlay">
|
|
|
|
<p>Video playback not supported</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
#end proc
|
|
|
|
#
|
2019-06-24 05:14:14 +02:00
|
|
|
#proc renderGif(gif: Gif): string =
|
|
|
|
<div class="attachments media-body" style="display: table-cell;">
|
2019-06-20 16:16:20 +02:00
|
|
|
<div class="gallery-row" style="max-height: unset;">
|
|
|
|
<div class="attachment image">
|
2019-06-24 05:14:14 +02:00
|
|
|
<video class="gif" poster=${gif.thumb.getSigUrl("pic")} autoplay muted loop>
|
|
|
|
<source src=${gif.url.getSigUrl("video")} type="video/mp4">
|
2019-06-20 16:16:20 +02:00
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
#end proc
|
|
|
|
#
|
|
|
|
#proc renderStats(tweet: Tweet): string =
|
|
|
|
<div class="tweet-stats">
|
|
|
|
<span class="tweet-stat">💬 ${$tweet.replies}</span>
|
|
|
|
<span class="tweet-stat">🔄 ${$tweet.retweets}</span>
|
|
|
|
<span class="tweet-stat">👍 ${$tweet.likes}</span>
|
|
|
|
</div>
|
|
|
|
#end proc
|
|
|
|
#
|
|
|
|
#proc renderTweet*(tweet: Tweet; class=""): string =
|
2019-06-21 04:35:59 +02:00
|
|
|
#if class.len > 0:
|
2019-06-20 16:16:20 +02:00
|
|
|
<div class="${class}">
|
2019-06-21 04:35:59 +02:00
|
|
|
#end if
|
2019-06-21 04:35:48 +02:00
|
|
|
<div class="status-el">
|
|
|
|
<div class="status-body">
|
|
|
|
${renderHeading(tweet)}
|
|
|
|
<div class="status-content-wrapper">
|
|
|
|
<div class="status-content media-body">
|
|
|
|
${linkifyText(xmltree.escape(tweet.text))}
|
2019-06-20 16:16:20 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-06-21 04:35:48 +02:00
|
|
|
#if tweet.photos.len > 0:
|
|
|
|
${renderMediaGroup(tweet)}
|
2019-06-24 05:14:14 +02:00
|
|
|
#elif tweet.video.isSome:
|
|
|
|
${renderVideo(tweet.video.get())}
|
2019-06-21 04:35:48 +02:00
|
|
|
#elif tweet.gif.isSome:
|
2019-06-24 05:14:14 +02:00
|
|
|
${renderGif(tweet.gif.get())}
|
2019-06-24 08:07:36 +02:00
|
|
|
#elif tweet.quote.isSome:
|
|
|
|
${renderQuote(tweet.quote.get())}
|
2019-06-21 04:35:48 +02:00
|
|
|
#end if
|
|
|
|
${renderStats(tweet)}
|
2019-06-20 16:16:20 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-06-21 04:35:59 +02:00
|
|
|
#if class.len > 0:
|
|
|
|
</div>
|
|
|
|
#end if
|
2019-06-20 16:16:20 +02:00
|
|
|
#end proc
|