stats on embeds
This commit is contained in:
parent
71b19ae72b
commit
1fcf017359
@ -12,6 +12,19 @@ export router_utils
|
||||
export api, formatters
|
||||
export status, mastoapi
|
||||
|
||||
proc formatStat*(stat: int): string =
|
||||
#if stat > 1000000000000:
|
||||
# result = formatBiggestFloat(stat / 1000000000000, ffDecimal, precision = 1) & "T"
|
||||
#el
|
||||
if stat > 1000000000:
|
||||
result = formatBiggestFloat(stat / 1000000000, ffDecimal, precision = 1) & "B"
|
||||
elif stat > 1000000:
|
||||
result = formatBiggestFloat(stat / 1000000, ffDecimal, precision = 1) & "M"
|
||||
elif stat > 1000:
|
||||
result = formatBiggestFloat(stat / 1000, ffDecimal, precision = 1) & "K"
|
||||
else:
|
||||
result = $stat
|
||||
|
||||
proc createStatusRouter*(cfg: Config) =
|
||||
router status:
|
||||
get "/@name/status/@id/@reactors":
|
||||
@ -245,11 +258,27 @@ proc createStatusRouter*(cfg: Config) =
|
||||
else:
|
||||
query = &"photo:{realMediaIndex}"
|
||||
|
||||
var stats: seq[string] = @[]
|
||||
if tweet.stats.replies > 0:
|
||||
stats.add("↩ " & formatStat(tweet.stats.replies))
|
||||
if tweet.stats.retweets > 0:
|
||||
stats.add("🔁 " & formatStat(tweet.stats.retweets))
|
||||
if tweet.stats.quotes > 0:
|
||||
stats.add("↘ " & formatStat(tweet.stats.quotes))
|
||||
if tweet.stats.likes > 0:
|
||||
stats.add("♥ " & formatStat(tweet.stats.likes))
|
||||
if tweet.stats.bookmarks > 0:
|
||||
stats.add("🔖 " & formatStat(tweet.stats.bookmarks))
|
||||
if tweet.stats.views > 0:
|
||||
stats.add("👁️ " & formatStat(tweet.stats.views))
|
||||
|
||||
let statsStr = stats.join(" ")
|
||||
|
||||
let html = renderConversation(conv, prefs, getPath() & "#m")
|
||||
resp renderMain(html, request, cfg, prefs, title, desc, ogTitle,
|
||||
images=images, video=video, avatar=avatar, time=time,
|
||||
context=context, contextUrl=contextUrl, id=id, media=query
|
||||
)
|
||||
context=context, contextUrl=contextUrl, id=id,
|
||||
media=query, stats=statsStr)
|
||||
|
||||
get "/@name/statuses/@id/?@m?/?@i?":
|
||||
redirect("/$1/status/$2" % [@"name", @"id"])
|
||||
|
||||
@ -39,8 +39,8 @@ proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode =
|
||||
proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
|
||||
video=""; images: seq[Image] = @[]; banner=""; ogTitle="";
|
||||
rss=""; canonical=""; avatar=""; context=""; contextUrl="";
|
||||
id=""; time: Option[DateTime] = none(DateTime); media=""
|
||||
): VNode =
|
||||
id=""; time: Option[DateTime] = none(DateTime); media="";
|
||||
stats = ""): VNode =
|
||||
var theme = prefs.theme.toTheme
|
||||
if "theme" in req.params:
|
||||
theme = req.params["theme"].toTheme
|
||||
@ -106,13 +106,19 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
|
||||
meta(property="og:locale", content="en_US")
|
||||
|
||||
var siteName = "Nitter"
|
||||
if time.isSome and not isDiscord:
|
||||
if time.isSome:
|
||||
let timeObj = time.get
|
||||
let timeStr = $timeObj
|
||||
meta(property="og:article:published_time", content=timeStr)
|
||||
|
||||
let formattedTime = timeObj.format("yyyy/MM/dd HH:mm:ss")
|
||||
siteName = &"Nitter • {formattedTime}"
|
||||
if not isDiscord:
|
||||
let formattedTime = timeObj.format("yyyy/MM/dd HH:mm:ss")
|
||||
siteName &= " • {formattedTime}"
|
||||
if stats.len > 0:
|
||||
siteName &= "\n" & stats
|
||||
|
||||
if isDiscord and stats.len > 0:
|
||||
siteName &= " • " & stats
|
||||
|
||||
meta(property="og:site_name", content=siteName)
|
||||
|
||||
@ -189,13 +195,14 @@ proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs;
|
||||
titleText=""; desc=""; ogTitle=""; rss=""; video="";
|
||||
images: seq[Image] = @[]; banner=""; avatar=""; context="";
|
||||
contextUrl=""; id=""; time: Option[DateTime] = none(DateTime);
|
||||
media=""): string =
|
||||
media=""; stats=""): string =
|
||||
|
||||
let canonical = getTwitterLink(req.path, req.params)
|
||||
|
||||
let node = buildHtml(html(lang="en")):
|
||||
renderHead(prefs, cfg, req, titleText, desc, video, images, banner, ogTitle,
|
||||
rss, canonical, avatar, context, contextUrl, id, time, media)
|
||||
rss, canonical, avatar, context, contextUrl, id, time, media,
|
||||
stats)
|
||||
|
||||
body:
|
||||
renderNavbar(cfg, req, rss, canonical)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user