parent
58795b5f1c
commit
cd1fd532e6
|
@ -15,7 +15,7 @@ proc redisKey*(page, name, cursor: string): string =
|
|||
if cursor.len > 0:
|
||||
result &= ":" & cursor
|
||||
|
||||
proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.} =
|
||||
proc timelineRss*(req: Request; cfg: Config; query: Query; tab, param: string): Future[Rss] {.async.} =
|
||||
var profile: Profile
|
||||
let
|
||||
name = req.params.getOrDefault("name")
|
||||
|
@ -39,7 +39,7 @@ proc timelineRss*(req: Request; cfg: Config; query: Query): Future[Rss] {.async.
|
|||
return Rss(feed: profile.user.username, cursor: "suspended")
|
||||
|
||||
if profile.user.fullname.len > 0:
|
||||
let rss = renderTimelineRss(profile, cfg, multi=(names.len > 1))
|
||||
let rss = renderTimelineRss(profile, cfg, tab, param, multi=(names.len > 1))
|
||||
return Rss(feed: rss, cursor: profile.tweets.bottom)
|
||||
|
||||
template respRss*(rss, page) =
|
||||
|
@ -94,7 +94,7 @@ proc createRssRouter*(cfg: Config) =
|
|||
if rss.cursor.len > 0:
|
||||
respRss(rss, "User")
|
||||
|
||||
rss = await timelineRss(request, cfg, Query(fromUser: @[name]))
|
||||
rss = await timelineRss(request, cfg, Query(fromUser: @[name]), "", "")
|
||||
|
||||
await cacheRss(key, rss)
|
||||
respRss(rss, "User")
|
||||
|
@ -113,8 +113,10 @@ proc createRssRouter*(cfg: Config) =
|
|||
of "search": initQuery(params(request), name=name)
|
||||
else: Query(fromUser: @[name])
|
||||
|
||||
let param = if tab != "search": ""
|
||||
else: genQueryUrl(query)
|
||||
let searchKey = if tab != "search": ""
|
||||
else: ":" & $hash(genQueryUrl(query))
|
||||
else: ":" & $hash(param)
|
||||
|
||||
let key = redisKey(tab, name & searchKey, getCursor())
|
||||
|
||||
|
@ -122,7 +124,7 @@ proc createRssRouter*(cfg: Config) =
|
|||
if rss.cursor.len > 0:
|
||||
respRss(rss, "User")
|
||||
|
||||
rss = await timelineRss(request, cfg, query)
|
||||
rss = await timelineRss(request, cfg, query, tab, param)
|
||||
|
||||
await cacheRss(key, rss)
|
||||
respRss(rss, "User")
|
||||
|
|
|
@ -82,8 +82,20 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}
|
|||
#end for
|
||||
#end proc
|
||||
#
|
||||
#proc renderTimelineRss*(profile: Profile; cfg: Config; multi=false): string =
|
||||
#proc renderTimelineRss*(profile: Profile; cfg: Config; tab, param: string; multi=false): string =
|
||||
#let urlPrefix = getUrlPrefix(cfg)
|
||||
#var atomLink = &"{urlPrefix}/{profile.user.username}"
|
||||
#var link = &"{urlPrefix}/{profile.user.username}"
|
||||
#if tab != "":
|
||||
# atomLink &= "/" & tab
|
||||
# link &= "/" & tab
|
||||
#end if
|
||||
#atomLink &= "/rss"
|
||||
#if param != "":
|
||||
# let escParam = xmltree.escape(param)
|
||||
# atomLink &= "?" & escParam
|
||||
# link &= "?" & escParam
|
||||
#end if
|
||||
#result = ""
|
||||
#let handle = (if multi: "" else: "@") & profile.user.username
|
||||
#var title = profile.user.fullname
|
||||
|
@ -93,9 +105,9 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
||||
<channel>
|
||||
<atom:link href="${urlPrefix}/${profile.user.username}/rss" rel="self" type="application/rss+xml" />
|
||||
<atom:link href="${atomLink}" rel="self" type="application/rss+xml" />
|
||||
<title>${title}</title>
|
||||
<link>${urlPrefix}/${profile.user.username}</link>
|
||||
<link>${link}</link>
|
||||
<description>${getDescription(handle, cfg)}</description>
|
||||
<language>en-us</language>
|
||||
<ttl>40</ttl>
|
||||
|
@ -131,15 +143,16 @@ ${renderRssTweets(tweets, cfg)}
|
|||
#end proc
|
||||
#
|
||||
#proc renderSearchRss*(tweets: seq[Tweets]; name, param: string; cfg: Config): string =
|
||||
#let link = &"{getUrlPrefix(cfg)}/search"
|
||||
#let urlPrefix = getUrlPrefix(cfg)
|
||||
#let escName = xmltree.escape(name)
|
||||
#let escParam = xmltree.escape(param)
|
||||
#result = ""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
||||
<channel>
|
||||
<atom:link href="${link}" rel="self" type="application/rss+xml" />
|
||||
<atom:link href="${urlPrefix}/search/rss?${escParam}" rel="self" type="application/rss+xml" />
|
||||
<title>Search results for "${escName}"</title>
|
||||
<link>${link}</link>
|
||||
<link>${urlPrefix}/search?${escParam}</link>
|
||||
<description>${getDescription(&"Search \"{escName}\"", cfg)}</description>
|
||||
<language>en-us</language>
|
||||
<ttl>40</ttl>
|
||||
|
|
Loading…
Reference in New Issue