Use strformat more
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import asyncdispatch, strutils, options
|
||||
import asyncdispatch, strutils, strformat, options
|
||||
import jester, karax/vdom
|
||||
import ".."/[types, api]
|
||||
import ../views/[embed, tweet, general]
|
||||
@@ -31,6 +31,6 @@ proc createEmbedRouter*(cfg: Config) =
|
||||
let id = @"id"
|
||||
|
||||
if id.len > 0:
|
||||
redirect("/i/status/" & id & "/embed")
|
||||
redirect(&"/i/status/{id}/embed")
|
||||
else:
|
||||
resp Http404
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import strutils, uri
|
||||
import strutils, strformat, uri
|
||||
|
||||
import jester
|
||||
|
||||
@@ -10,14 +10,17 @@ export getListTimeline, getGraphList
|
||||
|
||||
template respList*(list, timeline, title, vnode: typed) =
|
||||
if list.id.len == 0 or list.name.len == 0:
|
||||
resp Http404, showError("List " & @"id" & " not found", cfg)
|
||||
resp Http404, showError(&"""List "{@"id"}" not found""", cfg)
|
||||
|
||||
let
|
||||
html = renderList(vnode, timeline.query, list)
|
||||
rss = "/i/lists/$1/rss" % [@"id"]
|
||||
rss = &"""/i/lists/{@"id"}/rss"""
|
||||
|
||||
resp renderMain(html, request, cfg, prefs, titleText=title, rss=rss, banner=list.banner)
|
||||
|
||||
proc title*(list: List): string =
|
||||
&"@{list.username}/{list.name}"
|
||||
|
||||
proc createListRouter*(cfg: Config) =
|
||||
router list:
|
||||
get "/@name/lists/@slug/?":
|
||||
@@ -28,24 +31,22 @@ proc createListRouter*(cfg: Config) =
|
||||
slug = decodeUrl(@"slug")
|
||||
list = await getCachedList(@"name", slug)
|
||||
if list.id.len == 0:
|
||||
resp Http404, showError("List \"" & @"slug" & "\" not found", cfg)
|
||||
redirect("/i/lists/" & list.id)
|
||||
resp Http404, showError(&"""List "{@"slug"}" not found""", cfg)
|
||||
redirect(&"/i/lists/{list.id}")
|
||||
|
||||
get "/i/lists/@id/?":
|
||||
cond '.' notin @"id"
|
||||
let
|
||||
prefs = cookiePrefs()
|
||||
list = await getCachedList(id=(@"id"))
|
||||
title = "@" & list.username & "/" & list.name
|
||||
timeline = await getListTimeline(list.id, getCursor())
|
||||
vnode = renderTimelineTweets(timeline, prefs, request.path)
|
||||
respList(list, timeline, title, vnode)
|
||||
respList(list, timeline, list.title, vnode)
|
||||
|
||||
get "/i/lists/@id/members":
|
||||
cond '.' notin @"id"
|
||||
let
|
||||
prefs = cookiePrefs()
|
||||
list = await getCachedList(id=(@"id"))
|
||||
title = "@" & list.username & "/" & list.name
|
||||
members = await getGraphListMembers(list, getCursor())
|
||||
respList(list, members, title, renderTimelineUsers(members, prefs, request.path))
|
||||
respList(list, members, list.title, renderTimelineUsers(members, prefs, request.path))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import asyncdispatch, strutils, tables, times, hashes, uri
|
||||
import asyncdispatch, strutils, strformat, tables, times, hashes, uri
|
||||
|
||||
import jester
|
||||
|
||||
@@ -42,8 +42,8 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
|
||||
template respRss*(rss, page) =
|
||||
if rss.cursor.len == 0:
|
||||
let info = case page
|
||||
of "User": " \"$1\" " % @"name"
|
||||
of "List": " $1 " % @"id"
|
||||
of "User": &""" "{@"name"}" """
|
||||
of "List": &""" "{@"id"}" """
|
||||
else: " "
|
||||
|
||||
resp Http404, showError(page & info & "not found", cfg)
|
||||
@@ -67,7 +67,7 @@ proc createRssRouter*(cfg: Config) =
|
||||
|
||||
let
|
||||
cursor = getCursor()
|
||||
key = "search:" & $hash(genQueryUrl(query)) & ":" & cursor
|
||||
key = &"search:{hash(genQueryUrl(query))}:cursor"
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
@@ -86,7 +86,7 @@ proc createRssRouter*(cfg: Config) =
|
||||
let
|
||||
cursor = getCursor()
|
||||
name = @"name"
|
||||
key = "twitter:" & name & ":" & cursor
|
||||
key = &"twitter:{name}:{cursor}"
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
@@ -109,7 +109,7 @@ proc createRssRouter*(cfg: Config) =
|
||||
of "search": initQuery(params(request), name=name)
|
||||
else: Query(fromUser: @[name])
|
||||
|
||||
var key = @"tab" & ":" & @"name" & ":"
|
||||
var key = &"""{@"tab"}:{@"name"}:"""
|
||||
if @"tab" == "search":
|
||||
key &= $hash(genQueryUrl(query)) & ":"
|
||||
key &= getCursor()
|
||||
@@ -132,11 +132,11 @@ proc createRssRouter*(cfg: Config) =
|
||||
cursor = getCursor()
|
||||
|
||||
if list.id.len == 0:
|
||||
resp Http404, showError("List \"" & @"slug" & "\" not found", cfg)
|
||||
resp Http404, showError(&"""List "{@"slug"}" not found""", cfg)
|
||||
|
||||
let url = "/i/lists/" & list.id & "/rss"
|
||||
let url = &"/i/lists/{list.id}/rss"
|
||||
if cursor.len > 0:
|
||||
redirect(url & "?cursor=" & encodeUrl(cursor, false))
|
||||
redirect(&"{url}?cursor={encodeUrl(cursor, false)}")
|
||||
else:
|
||||
redirect(url)
|
||||
|
||||
@@ -146,7 +146,7 @@ proc createRssRouter*(cfg: Config) =
|
||||
cursor = getCursor()
|
||||
key =
|
||||
if cursor.len == 0: "lists:" & @"id"
|
||||
else: "lists:" & @"id" & ":" & cursor
|
||||
else: &"""lists:{@"id"}:{cursor}"""
|
||||
|
||||
var rss = await getCachedRss(key)
|
||||
if rss.cursor.len > 0:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import strutils, uri
|
||||
import strutils, strformat, uri
|
||||
|
||||
import jester
|
||||
|
||||
@@ -37,7 +37,7 @@ proc createSearchRouter*(cfg: Config) =
|
||||
resp Http404, showError("Invalid search", cfg)
|
||||
|
||||
get "/hashtag/@hash":
|
||||
redirect("/search?q=" & encodeUrl("#" & @"hash"))
|
||||
redirect(&"""/search?q={encodeUrl("#" & @"hash")}""")
|
||||
|
||||
get "/opensearch":
|
||||
let url = getUrlPrefix(cfg) & "/search?q="
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import asyncdispatch, strutils, sequtils, uri, options, times
|
||||
import asyncdispatch, strutils, strformat, sequtils, uri, options, times
|
||||
import jester, karax/vdom
|
||||
|
||||
import router_utils
|
||||
@@ -102,7 +102,7 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; prefs: Prefs;
|
||||
template respTimeline*(timeline: typed) =
|
||||
let t = timeline
|
||||
if t.len == 0:
|
||||
resp Http404, showError("User \"" & @"name" & "\" not found", cfg)
|
||||
resp Http404, showError(&"""User "{@"name"}" not found""", cfg)
|
||||
resp t
|
||||
|
||||
template respUserId*() =
|
||||
|
||||
Reference in New Issue
Block a user