Support RSS for multi-timelines
This commit is contained in:
parent
fba7ed2a19
commit
7c35875fbf
4 changed files with 32 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import strutils, sequtils
|
||||||
import ../utils, ../prefs
|
import ../utils, ../prefs
|
||||||
export utils, prefs
|
export utils, prefs
|
||||||
|
|
||||||
|
@ -9,3 +10,6 @@ template getPath*(): untyped {.dirty.} =
|
||||||
|
|
||||||
template refPath*(): untyped {.dirty.} =
|
template refPath*(): untyped {.dirty.} =
|
||||||
if @"referer".len > 0: @"referer" else: "/"
|
if @"referer".len > 0: @"referer" else: "/"
|
||||||
|
|
||||||
|
proc getNames*(name: string): seq[string] =
|
||||||
|
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||||
|
|
|
@ -9,11 +9,23 @@ import ../views/general
|
||||||
include "../views/rss.nimf"
|
include "../views/rss.nimf"
|
||||||
|
|
||||||
proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
|
proc showRss*(name, hostname: string; query: Query): Future[string] {.async.} =
|
||||||
let (profile, timeline) =
|
var profile: Profile
|
||||||
await fetchSingleTimeline(name, "", getAgent(), query, media=false)
|
var timeline: Timeline
|
||||||
|
let names = getNames(name)
|
||||||
|
if names.len == 1:
|
||||||
|
(profile, timeline) =
|
||||||
|
await fetchSingleTimeline(names[0], "", getAgent(), query, media=false)
|
||||||
|
else:
|
||||||
|
timeline = await fetchMultiTimeline(names, "", getAgent(), query, media=false)
|
||||||
|
# this is kinda dumb
|
||||||
|
profile = Profile(
|
||||||
|
username: name,
|
||||||
|
fullname: names.join(" | "),
|
||||||
|
userpic: "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
|
||||||
|
)
|
||||||
|
|
||||||
if timeline != nil:
|
if timeline != nil:
|
||||||
return renderTimelineRss(timeline, profile, hostname)
|
return renderTimelineRss(timeline, profile, hostname, multi=(names.len > 1))
|
||||||
|
|
||||||
template respRss*(rss: typed) =
|
template respRss*(rss: typed) =
|
||||||
if rss.len == 0:
|
if rss.len == 0:
|
||||||
|
|
|
@ -38,13 +38,13 @@ proc fetchSingleTimeline*(name, after, agent: string; query: Query;
|
||||||
if profile.username.len == 0: return
|
if profile.username.len == 0: return
|
||||||
return (profile, timeline)
|
return (profile, timeline)
|
||||||
|
|
||||||
proc fetchMultiTimeline*(names: seq[string]; after, agent: string;
|
proc fetchMultiTimeline*(names: seq[string]; after, agent: string; query: Query;
|
||||||
query: Query): Future[Timeline] {.async.} =
|
media=true): Future[Timeline] {.async.} =
|
||||||
var q = query
|
var q = query
|
||||||
q.fromUser = names
|
q.fromUser = names
|
||||||
if q.kind == posts and "replies" notin q.excludes:
|
if q.kind == posts and "replies" notin q.excludes:
|
||||||
q.excludes.add "replies"
|
q.excludes.add "replies"
|
||||||
return await getSearch[Tweet](q, after, agent)
|
return await getSearch[Tweet](q, after, agent, media)
|
||||||
|
|
||||||
proc get*(req: Request; key: string): string =
|
proc get*(req: Request; key: string): string =
|
||||||
if key in params(req): params(req)[key]
|
if key in params(req): params(req)[key]
|
||||||
|
@ -56,13 +56,13 @@ proc showTimeline*(request: Request; query: Query; cfg: Config; rss: string): Fu
|
||||||
prefs = cookiePrefs()
|
prefs = cookiePrefs()
|
||||||
name = request.get("name")
|
name = request.get("name")
|
||||||
after = request.get("max_position")
|
after = request.get("max_position")
|
||||||
names = name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
names = getNames(name)
|
||||||
|
|
||||||
if names.len != 1:
|
if names.len != 1:
|
||||||
let
|
let
|
||||||
timeline = await fetchMultiTimeline(names, after, agent, query)
|
timeline = await fetchMultiTimeline(names, after, agent, query)
|
||||||
html = renderTweetSearch(timeline, prefs, getPath())
|
html = renderTweetSearch(timeline, prefs, getPath())
|
||||||
return renderMain(html, request, cfg, "Multi")
|
return renderMain(html, request, cfg, "Multi", rss=rss)
|
||||||
|
|
||||||
let
|
let
|
||||||
rail = getPhotoRail(names[0], agent, skip=(query.kind == media))
|
rail = getPhotoRail(names[0], agent, skip=(query.kind == media))
|
||||||
|
|
|
@ -56,20 +56,24 @@
|
||||||
#end for
|
#end for
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
#proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string): string =
|
#proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string; multi=false): string =
|
||||||
#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us")
|
#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us")
|
||||||
#result = ""
|
#result = ""
|
||||||
|
#let user = (if multi: "" else: "@") & profile.username
|
||||||
|
#var title = profile.fullname
|
||||||
|
#if not multi: title &= " / " & user
|
||||||
|
#end if
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
||||||
<channel>
|
<channel>
|
||||||
<atom:link href="https://${hostname}/${profile.username}/rss" rel="self" type="application/rss+xml" />
|
<atom:link href="https://${hostname}/${profile.username}/rss" rel="self" type="application/rss+xml" />
|
||||||
<title>${profile.fullname} / @${profile.username}</title>
|
<title>${title}</title>
|
||||||
<link>https://${hostname}/${profile.username}</link>
|
<link>https://${hostname}/${profile.username}</link>
|
||||||
<description>Twitter feed for: @${profile.username}. Generated by ${hostname}</description>
|
<description>Twitter feed for: ${user}. Generated by ${hostname}</description>
|
||||||
<language>en-us</language>
|
<language>en-us</language>
|
||||||
<ttl>40</ttl>
|
<ttl>40</ttl>
|
||||||
<image>
|
<image>
|
||||||
<title>${profile.fullname} / @${profile.username}</title>
|
<title>${title}</title>
|
||||||
<link>https://${hostname}/${profile.username}</link>
|
<link>https://${hostname}/${profile.username}</link>
|
||||||
<url>https://${hostname}${getPicUrl(profile.getUserPic(style="_400x400"))}</url>
|
<url>https://${hostname}${getPicUrl(profile.getUserPic(style="_400x400"))}</url>
|
||||||
<width>128</width>
|
<width>128</width>
|
||||||
|
|
Loading…
Reference in a new issue