Support rss for custom search

This commit is contained in:
Zed 2019-09-20 03:35:27 +02:00
parent bd4895f6fd
commit df3001ae95
3 changed files with 19 additions and 11 deletions

View file

@ -68,10 +68,10 @@ proc genQueryParam*(query: Query): string =
for f in query.filters:
filters.add "filter:" & f
for i in query.includes:
filters.add "include:" & i
for e in query.excludes:
filters.add "-filter:" & e
for i in query.includes:
filters.add "include:" & i
result = strip(param & filters.join(&" {query.sep} "))
if query.since.len > 0:
@ -83,7 +83,7 @@ proc genQueryParam*(query: Query): string =
if query.text.len > 0:
result &= " " & query.text
proc genQueryUrl*(query: Query): string =
proc genQueryUrl*(query: Query; onlyParam=false): string =
if query.fromUser.len > 0:
result = "/" & query.fromUser.join(",")
@ -93,6 +93,9 @@ proc genQueryUrl*(query: Query): string =
if query.kind notin {custom, users}:
return result & &"/{query.kind}?"
if onlyParam:
result = ""
else:
result &= &"/search?"
var params = @[&"kind={query.kind}"]
@ -102,7 +105,7 @@ proc genQueryUrl*(query: Query): string =
params.add "f-" & f & "=on"
for e in query.excludes:
params.add "e-" & e & "=on"
for i in query.excludes:
for i in query.includes:
params.add "i-" & i & "=on"
if query.since.len > 0:

View file

@ -30,3 +30,7 @@ proc createRssRouter*(cfg: Config) =
get "/@name/media/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", getMediaQuery(@"name")))
get "/@name/search/rss":
cond '.' notin @"name"
respRss(await showRss(@"name", initQuery(params(request), name=(@"name"))))

View file

@ -80,12 +80,6 @@ proc createTimelineRouter*(cfg: Config) =
respTimeline(await showTimeline(@"name", @"after", Query(), cookiePrefs(),
getPath(), cfg.title, rss))
get "/@name/search":
cond '.' notin @"name"
let query = initQuery(params(request), name=(@"name"))
respTimeline(await showTimeline(@"name", @"after", query, cookiePrefs(),
getPath(), cfg.title, ""))
get "/@name/replies":
cond '.' notin @"name"
let rss = "/$1/replies/rss" % @"name"
@ -98,6 +92,13 @@ proc createTimelineRouter*(cfg: Config) =
respTimeline(await showTimeline(@"name", @"after", getMediaQuery(@"name"),
cookiePrefs(), getPath(), cfg.title, rss))
get "/@name/search":
cond '.' notin @"name"
let query = initQuery(params(request), name=(@"name"))
let rss = "/$1/search/rss?$2" % [@"name", genQueryUrl(query, onlyParam=true)]
respTimeline(await showTimeline(@"name", @"after", query, cookiePrefs(),
getPath(), cfg.title, rss))
get "/@name/status/@id":
cond '.' notin @"name"
let prefs = cookiePrefs()