mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-12 02:56:29 +00:00
Support tweet locations
This commit is contained in:
parent
80d6191e74
commit
f8f4487c33
7 changed files with 34 additions and 5 deletions
|
@ -103,3 +103,8 @@ proc getTwitterLink*(path: string; params: Table[string, string]): string =
|
||||||
result = $(parseUri("https://twitter.com") / path ? p)
|
result = $(parseUri("https://twitter.com") / path ? p)
|
||||||
if username.len > 0:
|
if username.len > 0:
|
||||||
result = result.replace("/" & username, "")
|
result = result.replace("/" & username, "")
|
||||||
|
|
||||||
|
proc getLocation*(u: Profile | Tweet): (string, string) =
|
||||||
|
let loc = u.location.split(":")
|
||||||
|
let url = if loc.len > 1: "/search?q=place:" & loc[1] else: ""
|
||||||
|
(loc[0], url)
|
||||||
|
|
|
@ -108,6 +108,7 @@ proc parseTweet*(node: XmlNode): Tweet =
|
||||||
stats: parseTweetStats(tweet),
|
stats: parseTweetStats(tweet),
|
||||||
reply: parseTweetReply(tweet),
|
reply: parseTweetReply(tweet),
|
||||||
mediaTags: getMediaTags(tweet),
|
mediaTags: getMediaTags(tweet),
|
||||||
|
location: getTweetLocation(tweet),
|
||||||
hasThread: tweet.select(".content > .self-thread-context") != nil,
|
hasThread: tweet.select(".content > .self-thread-context") != nil,
|
||||||
pinned: "pinned" in tweet.attr("class"),
|
pinned: "pinned" in tweet.attr("class"),
|
||||||
available: true
|
available: true
|
||||||
|
|
|
@ -285,3 +285,9 @@ proc getMediaTags*(node: XmlNode): seq[Profile] =
|
||||||
let un = user["screen_name"].getStr
|
let un = user["screen_name"].getStr
|
||||||
if un notin usernames: continue
|
if un notin usernames: continue
|
||||||
result.add Profile(username: un, fullname: user["name"].getStr)
|
result.add Profile(username: un, fullname: user["name"].getStr)
|
||||||
|
|
||||||
|
proc getTweetLocation*(node: XmlNode): string =
|
||||||
|
let geo = node.select(".js-geo-pivot-link")
|
||||||
|
if geo == nil: return
|
||||||
|
result = geo.innerText().stripText()
|
||||||
|
result &= ":" & geo.attr("data-place-id")
|
||||||
|
|
|
@ -128,6 +128,10 @@
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tweet-geo {
|
||||||
|
color: var(--fg_faded);
|
||||||
|
}
|
||||||
|
|
||||||
.replying-to {
|
.replying-to {
|
||||||
color: var(--fg_faded);
|
color: var(--fg_faded);
|
||||||
margin: -2px 0 4px;
|
margin: -2px 0 4px;
|
||||||
|
@ -168,6 +172,7 @@
|
||||||
.show-thread {
|
.show-thread {
|
||||||
display: block;
|
display: block;
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
|
padding-top: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.unavailable-box {
|
.unavailable-box {
|
||||||
|
|
|
@ -147,6 +147,7 @@ type
|
||||||
hasThread*: bool
|
hasThread*: bool
|
||||||
available*: bool
|
available*: bool
|
||||||
tombstone*: string
|
tombstone*: string
|
||||||
|
location*: string
|
||||||
stats*: TweetStats
|
stats*: TweetStats
|
||||||
retweet*: Option[Retweet]
|
retweet*: Option[Retweet]
|
||||||
attribution*: Option[Profile]
|
attribution*: Option[Profile]
|
||||||
|
|
|
@ -31,11 +31,11 @@ proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode =
|
||||||
if profile.location.len > 0:
|
if profile.location.len > 0:
|
||||||
tdiv(class="profile-location"):
|
tdiv(class="profile-location"):
|
||||||
span: icon "location"
|
span: icon "location"
|
||||||
let loc = profile.location.split(":")
|
let (place, url) = profile.getLocation()
|
||||||
if loc.len > 1:
|
if url.len > 1:
|
||||||
a(href=("/search?q=place:" & loc[1])): text loc[0]
|
a(href=url): text place
|
||||||
else:
|
else:
|
||||||
span: text loc[0]
|
span: text place
|
||||||
|
|
||||||
if profile.website.len > 0:
|
if profile.website.len > 0:
|
||||||
tdiv(class="profile-website"):
|
tdiv(class="profile-website"):
|
||||||
|
|
|
@ -245,6 +245,17 @@ proc renderQuote(quote: Quote; prefs: Prefs): VNode =
|
||||||
a(class="show-thread", href=getLink(quote)):
|
a(class="show-thread", href=getLink(quote)):
|
||||||
text "Show this thread"
|
text "Show this thread"
|
||||||
|
|
||||||
|
proc renderLocation*(tweet: Tweet): string =
|
||||||
|
let (place, url) = tweet.getLocation()
|
||||||
|
if place.len == 0: return
|
||||||
|
let node = buildHtml(span(class="tweet-geo")):
|
||||||
|
text " – at "
|
||||||
|
if url.len > 1:
|
||||||
|
a(href=url): text place
|
||||||
|
else:
|
||||||
|
text place
|
||||||
|
return $node
|
||||||
|
|
||||||
proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
|
proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
|
||||||
index=0; total=(-1); last=false; showThread=false;
|
index=0; total=(-1); last=false; showThread=false;
|
||||||
mainTweet=false): VNode =
|
mainTweet=false): VNode =
|
||||||
|
@ -272,7 +283,7 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
|
||||||
renderReply(tweet)
|
renderReply(tweet)
|
||||||
|
|
||||||
tdiv(class="tweet-content media-body", dir="auto"):
|
tdiv(class="tweet-content media-body", dir="auto"):
|
||||||
verbatim replaceUrl(tweet.text, prefs)
|
verbatim replaceUrl(tweet.text, prefs) & renderLocation(tweet)
|
||||||
|
|
||||||
if tweet.attribution.isSome:
|
if tweet.attribution.isSome:
|
||||||
renderAttribution(tweet.attribution.get())
|
renderAttribution(tweet.attribution.get())
|
||||||
|
|
Loading…
Reference in a new issue