Support media tags
This commit is contained in:
@@ -107,6 +107,7 @@ proc parseTweet*(node: XmlNode): Tweet =
|
||||
profile: parseTweetProfile(tweet),
|
||||
stats: parseTweetStats(tweet),
|
||||
reply: parseTweetReply(tweet),
|
||||
mediaTags: getMediaTags(tweet),
|
||||
hasThread: tweet.select(".content > .self-thread-context") != nil,
|
||||
pinned: "pinned" in tweet.attr("class"),
|
||||
available: true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import xmltree, strtabs, strformat, strutils, times, uri, options
|
||||
import xmltree, strtabs, strformat, strutils, times, uri, options, json
|
||||
import regex
|
||||
|
||||
import types, formatters
|
||||
@@ -276,3 +276,12 @@ proc getMoreReplies*(node: XmlNode): int64 =
|
||||
result = parseBiggestInt(text.split(" ")[0])
|
||||
except:
|
||||
result = -1
|
||||
|
||||
proc getMediaTags*(node: XmlNode): seq[Profile] =
|
||||
let usernames = node.attr("data-tagged")
|
||||
if usernames.len == 0: return
|
||||
let users = parseJson(node.attr("data-reply-to-users-json"))
|
||||
for user in users:
|
||||
let un = user["screen_name"].getStr
|
||||
if un notin usernames: continue
|
||||
result.add Profile(username: un, fullname: user["name"].getStr)
|
||||
|
||||
@@ -110,6 +110,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
.media-tag-block {
|
||||
padding-top: 5px;
|
||||
pointer-events: all;
|
||||
color: var(--fg_faded);
|
||||
|
||||
.icon-container {
|
||||
padding-right: 2px;
|
||||
}
|
||||
|
||||
.media-tag, .icon-container {
|
||||
color: var(--fg_faded);
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-container .media-tag-block {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.replying-to {
|
||||
color: var(--fg_faded);
|
||||
margin: -2px 0 4px;
|
||||
|
||||
@@ -150,6 +150,7 @@ type
|
||||
stats*: TweetStats
|
||||
retweet*: Option[Retweet]
|
||||
attribution*: Option[Profile]
|
||||
mediaTags*: seq[Profile]
|
||||
quote*: Option[Quote]
|
||||
card*: Option[Card]
|
||||
gif*: Option[Gif]
|
||||
|
||||
@@ -195,6 +195,15 @@ proc renderAttribution(profile: Profile): VNode =
|
||||
img(class="avatar", width="20", height="20", src=avatarUrl)
|
||||
strong: text profile.fullname
|
||||
|
||||
proc renderMediaTags(tags: seq[Profile]): VNode =
|
||||
buildHtml(tdiv(class="media-tag-block")):
|
||||
icon "user"
|
||||
for i, p in tags:
|
||||
a(class="media-tag", href=("/" & p.username), title=p.username):
|
||||
text p.fullname
|
||||
if i < tags.high:
|
||||
text ", "
|
||||
|
||||
proc renderQuoteMedia(quote: Quote): VNode =
|
||||
buildHtml(tdiv(class="quote-media-container")):
|
||||
if quote.thumb.len > 0:
|
||||
@@ -286,6 +295,9 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
|
||||
if mainTweet:
|
||||
p(class="tweet-published"): text getTweetTime(tweet)
|
||||
|
||||
if tweet.mediaTags.len > 0:
|
||||
renderMediaTags(tweet.mediaTags)
|
||||
|
||||
if not prefs.hideTweetStats:
|
||||
renderStats(tweet.stats, views)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user