Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS feeds for threads #409

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/routes/rss.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,34 @@ proc createRssRouter*(cfg: Config) =

await cacheRss(key, rss)
respRss(rss, "List")

get "/@name/status/@id/rss":
cond '.' notin @"name"
let name = @"name"
let id = @"id"

var key = name & "/" & id

var rss = await getCachedRss(key)
if rss.cursor.len > 0:
respRss(rss, "Tweet")

var conv = await getTweet(id)
if conv == nil or conv.tweet == nil or conv.tweet.id == 0:
var error = "Tweet not found"
if conv != nil and conv.tweet != nil and conv.tweet.tombstone.len > 0:
error = conv.tweet.tombstone
resp Http404, showError(error, cfg)

while conv.after.hasMore:
let newer_conv = await getTweet($conv.after.content[^1].id)
if newer_conv == nil or newer_conv.tweet == nil or newer_conv.tweet.id == 0:
break
conv = newer_conv

let lastThreadTweets = conv.before.content & @[conv.tweet] & conv.after.content
let feed = compress renderThreadRss(lastThreadTweets, name, id, cfg)
rss = Rss(feed: feed, cursor: $lastThreadTweets[0].id)

await cacheRss(key, rss)
respRss(rss, "Tweet")
4 changes: 3 additions & 1 deletion src/routes/status.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ proc createStatusRouter*(cfg: Config) =
elif card.video.isSome():
images = @[card.video.get().thumb]


let rss = "/$1/status/$2/rss" % [@"name", @"id"]
let html = renderConversation(conv, prefs, getPath() & "#m")
resp renderMain(html, request, cfg, prefs, title, desc, ogTitle,
images=images, video=video)
images=images, video=video, rss=rss)

get "/@name/@s/@id/@m/?@i?":
cond @"s" in ["status", "statuses"]
Expand Down
11 changes: 5 additions & 6 deletions src/views/general.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";

let ogType =
if video.len > 0: "video"
elif rss.len > 0: "object"
elif images.len > 0: "photo"
else: "article"

Expand Down Expand Up @@ -107,15 +106,15 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
meta(property="og:image", content=image)
meta(property="twitter:image:src", content=image)

if rss.len > 0:
meta(property="twitter:card", content="summary")
else:
meta(property="twitter:card", content="summary_large_image")

if video.len > 0:
meta(property="twitter:card", content="summary_large_image")
meta(property="og:video:url", content=video)
meta(property="og:video:secure_url", content=video)
meta(property="og:video:type", content="text/html")
elif images.len > 0:
meta(property="twitter:card", content="summary_large_image")
else:
meta(property="twitter:card", content="summary")

# this is last so images are also preloaded
# if this is done earlier, Chrome only preloads one image for some reason
Expand Down
17 changes: 17 additions & 0 deletions src/views/rss.nimf
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,20 @@ ${renderRssTweets(tweets, cfg)}
</channel>
</rss>
#end proc
#
#proc renderThreadRss*(tweets: seq[Tweet]; username, tweetId: string; cfg: Config): string =
#let urlPrefix = getUrlPrefix(cfg)
#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="${urlPrefix}/${username}/status/${tweetId}/rss" rel="self" type="application/rss+xml" />
<title>Thread for ${urlPrefix}/${username}/status/${tweetId}</title>
<link>${urlPrefix}/${username}/status/${tweetId}</link>
<description>${getDescription("Thread for " & urlPrefix & "/" & username & "/status/" & tweetId, cfg)}</description>
<language>en-us</language>
<ttl>40</ttl>
${renderRssTweets(tweets, cfg)}
</channel>
</rss>
#end proc