From d96550fcce018f7b2c7b967cc2e441cad602a89e Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 30 Dec 2021 04:18:40 +0100 Subject: [PATCH] Minor code improvements --- src/formatters.nim | 4 ++-- src/routes/search.nim | 5 ++--- src/routes/status.nim | 5 ++++- src/routes/timeline.nim | 13 ++++++++----- src/views/renderutils.nim | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index 6119024..b691e6c 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -28,7 +28,7 @@ const twitter = parseUri("https://twitter.com") proc getUrlPrefix*(cfg: Config): string = - if cfg.useHttps: "https://" & cfg.hostname + if cfg.useHttps: https & cfg.hostname else: "http://" & cfg.hostname proc stripHtml*(text: string): string = @@ -58,7 +58,7 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string = if prefs.replaceTwitter.len > 0 and (twRegex in result or tco in result): - result = result.replace(tco, "https://" & prefs.replaceTwitter & "/t.co") + result = result.replace(tco, https & prefs.replaceTwitter & "/t.co") result = result.replace(cards, prefs.replaceTwitter & "/cards") result = result.replace(twRegex, prefs.replaceTwitter) diff --git a/src/routes/search.nim b/src/routes/search.nim index 0fcd9ee..b3f8db7 100644 --- a/src/routes/search.nim +++ b/src/routes/search.nim @@ -4,7 +4,7 @@ import strutils, uri import jester import router_utils -import ".."/[query, types, api] +import ".."/[query, types, api, formatters] import ../views/[general, search] include "../views/opensearch.nimf" @@ -40,7 +40,6 @@ proc createSearchRouter*(cfg: Config) = redirect("/search?q=" & encodeUrl("#" & @"hash")) get "/opensearch": - var url = if cfg.useHttps: "https://" else: "http://" - url &= cfg.hostname & "/search?q=" + let url = getUrlPrefix(cfg) & "/search?q=" resp Http200, {"Content-Type": "application/opensearchdescription+xml"}, generateOpenSearchXML(cfg.title, cfg.hostname, url) diff --git a/src/routes/status.nim b/src/routes/status.nim index bad8569..70e31cb 100644 --- a/src/routes/status.nim +++ b/src/routes/status.nim @@ -18,6 +18,7 @@ proc createStatusRouter*(cfg: Config) = cond '.' notin @"name" let prefs = cookiePrefs() + # used for the infinite scroll feature if @"scroll".len > 0: let replies = await getReplies(@"id", getCursor()) if replies.content.len == 0: @@ -34,10 +35,12 @@ proc createStatusRouter*(cfg: Config) = error = conv.tweet.tombstone resp Http404, showError(error, cfg) - var + let title = pageTitle(conv.tweet) ogTitle = pageTitle(conv.tweet.profile) desc = conv.tweet.text + + var images = conv.tweet.photos video = "" diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index 02120d6..e904f2d 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -131,6 +131,7 @@ proc createTimelineRouter*(cfg: Config) = if names.len != 1: query.fromUser = names + # used for the infinite scroll feature if @"scroll".len > 0: if query.fromUser.len != 1: var timeline = await getSearch[Tweet](query, after) @@ -143,10 +144,12 @@ proc createTimelineRouter*(cfg: Config) = timeline.beginning = true resp $renderTimelineTweets(timeline, prefs, getPath()) - var rss = "/$1/$2/rss" % [@"name", @"tab"] - if @"tab".len == 0: - rss = "/$1/rss" % @"name" - elif @"tab" == "search": - rss &= "?" & genQueryUrl(query) + let rss = + if @"tab".len == 0: + "/$1/rss" % @"name" + elif @"tab" == "search": + "/$1/search/rss?$2" % [@"name", genQueryUrl(query)] + else: + "/$1/$2/rss" % [@"name", @"tab"] respTimeline(await showTimeline(request, query, cfg, prefs, rss, after)) diff --git a/src/views/renderutils.nim b/src/views/renderutils.nim index 0db28c8..4804144 100644 --- a/src/views/renderutils.nim +++ b/src/views/renderutils.nim @@ -31,7 +31,7 @@ proc linkUser*(profile: Profile, class=""): VNode = icon "lock", title="Protected account" proc linkText*(text: string; class=""): VNode = - let url = if "http" notin text: "http://" & text else: text + let url = if "http" notin text: https & text else: text buildHtml(): a(href=url, class=class): text text