parent
53a7113905
commit
8cae23dc7e
|
@ -25,7 +25,7 @@ template `@`(param: string): untyped =
|
||||||
proc initQuery*(pms: Table[string, string]; name=""): Query =
|
proc initQuery*(pms: Table[string, string]; name=""): Query =
|
||||||
result = Query(
|
result = Query(
|
||||||
kind: parseEnum[QueryKind](@"kind", custom),
|
kind: parseEnum[QueryKind](@"kind", custom),
|
||||||
text: @"text",
|
text: @"q",
|
||||||
filters: validFilters.filterIt("f-" & it in pms),
|
filters: validFilters.filterIt("f-" & it in pms),
|
||||||
excludes: validFilters.filterIt("e-" & it in pms),
|
excludes: validFilters.filterIt("e-" & it in pms),
|
||||||
since: @"since",
|
since: @"since",
|
||||||
|
@ -88,7 +88,7 @@ proc genQueryUrl*(query: Query): string =
|
||||||
|
|
||||||
var params = @[&"kind={query.kind}"]
|
var params = @[&"kind={query.kind}"]
|
||||||
if query.text.len > 0:
|
if query.text.len > 0:
|
||||||
params.add "text=" & encodeUrl(query.text)
|
params.add "q=" & encodeUrl(query.text)
|
||||||
for f in query.filters:
|
for f in query.filters:
|
||||||
params.add "f-" & f & "=on"
|
params.add "f-" & f & "=on"
|
||||||
for e in query.excludes:
|
for e in query.excludes:
|
||||||
|
|
|
@ -20,7 +20,7 @@ template respRss*(rss: typed) =
|
||||||
proc createRssRouter*(cfg: Config) =
|
proc createRssRouter*(cfg: Config) =
|
||||||
router rss:
|
router rss:
|
||||||
get "/search/rss":
|
get "/search/rss":
|
||||||
if @"text".len > 200:
|
if @"q".len > 200:
|
||||||
resp Http400, showError("Search input too long.", cfg.title)
|
resp Http400, showError("Search input too long.", cfg.title)
|
||||||
|
|
||||||
let query = initQuery(params(request))
|
let query = initQuery(params(request))
|
||||||
|
|
|
@ -11,7 +11,7 @@ export search
|
||||||
proc createSearchRouter*(cfg: Config) =
|
proc createSearchRouter*(cfg: Config) =
|
||||||
router search:
|
router search:
|
||||||
get "/search/?":
|
get "/search/?":
|
||||||
if @"text".len > 200:
|
if @"q".len > 200:
|
||||||
resp Http400, showError("Search input too long.", cfg.title)
|
resp Http400, showError("Search input too long.", cfg.title)
|
||||||
|
|
||||||
let prefs = cookiePrefs()
|
let prefs = cookiePrefs()
|
||||||
|
@ -19,8 +19,8 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
|
|
||||||
case query.kind
|
case query.kind
|
||||||
of userSearch:
|
of userSearch:
|
||||||
if "," in @"text":
|
if "," in @"q":
|
||||||
redirect("/" & @"text")
|
redirect("/" & @"q")
|
||||||
let users = await getSearch[Profile](query, @"after", getAgent())
|
let users = await getSearch[Profile](query, @"after", getAgent())
|
||||||
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
|
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
|
||||||
of custom:
|
of custom:
|
||||||
|
@ -32,4 +32,4 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
resp Http404, showError("Invalid search.", cfg.title)
|
resp Http404, showError("Invalid search.", cfg.title)
|
||||||
|
|
||||||
get "/hashtag/@hash":
|
get "/hashtag/@hash":
|
||||||
redirect("/search?text=" & encodeUrl("#" & @"hash"))
|
redirect("/search?q=" & encodeUrl("#" & @"hash"))
|
||||||
|
|
|
@ -24,7 +24,7 @@ proc renderSearch*(): VNode =
|
||||||
tdiv(class="search-bar"):
|
tdiv(class="search-bar"):
|
||||||
form(`method`="get", action="/search"):
|
form(`method`="get", action="/search"):
|
||||||
hiddenField("kind", "userSearch")
|
hiddenField("kind", "userSearch")
|
||||||
input(`type`="text", name="text", autofocus="", placeholder="Enter username...")
|
input(`type`="text", name="q", autofocus="", placeholder="Enter username...")
|
||||||
button(`type`="submit"): icon "search"
|
button(`type`="submit"): icon "search"
|
||||||
|
|
||||||
proc renderProfileTabs*(query: Query; username: string): VNode =
|
proc renderProfileTabs*(query: Query; username: string): VNode =
|
||||||
|
@ -58,7 +58,7 @@ proc renderSearchPanel*(query: Query): VNode =
|
||||||
let action = if user.len > 0: &"/{user}/search" else: "/search"
|
let action = if user.len > 0: &"/{user}/search" else: "/search"
|
||||||
buildHtml(form(`method`="get", action=action, class="search-field")):
|
buildHtml(form(`method`="get", action=action, class="search-field")):
|
||||||
hiddenField("kind", "custom")
|
hiddenField("kind", "custom")
|
||||||
genInput("text", "", query.text, "Enter search...",
|
genInput("q", "", query.text, "Enter search...",
|
||||||
class="pref-inline", autofocus=true)
|
class="pref-inline", autofocus=true)
|
||||||
button(`type`="submit"): icon "search"
|
button(`type`="submit"): icon "search"
|
||||||
if isPanelOpen(query):
|
if isPanelOpen(query):
|
||||||
|
@ -110,7 +110,7 @@ proc renderUserSearch*(users: Result[Profile]; prefs: Prefs): VNode =
|
||||||
tdiv(class="timeline-header"):
|
tdiv(class="timeline-header"):
|
||||||
form(`method`="get", action="/search", class="search-field"):
|
form(`method`="get", action="/search", class="search-field"):
|
||||||
hiddenField("kind", "userSearch")
|
hiddenField("kind", "userSearch")
|
||||||
genInput("text", "", users.query.text, "Enter username...", class="pref-inline")
|
genInput("q", "", users.query.text, "Enter username...", class="pref-inline")
|
||||||
button(`type`="submit"): icon "search"
|
button(`type`="submit"): icon "search"
|
||||||
|
|
||||||
renderSearchTabs(users.query)
|
renderSearchTabs(users.query)
|
||||||
|
|
Loading…
Reference in New Issue