Minor code improvements
This commit is contained in:
parent
eed4d4033f
commit
d96550fcce
5 changed files with 17 additions and 12 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = ""
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue