RSS feed includes all gallery images

This commit is contained in:
Cadence Fish 2020-01-27 04:15:53 +13:00
parent 5303ae1d4b
commit 1f253981b2
No known key found for this signature in database
GPG Key ID: 81015DF9AA8607E1
3 changed files with 21 additions and 10 deletions

View File

@ -52,7 +52,7 @@ class Timeline {
this.page_info = page.page_info this.page_info = page.page_info
} }
getFeed() { async fetchFeed() {
const feed = new RSS({ const feed = new RSS({
title: `@${this.user.data.username}`, title: `@${this.user.data.username}`,
feed_url: `${config.website_origin}/u/${this.user.data.username}/rss.xml`, feed_url: `${config.website_origin}/u/${this.user.data.username}/rss.xml`,
@ -63,9 +63,9 @@ class Timeline {
ttl: this.user.getTtl(1000*60) // scale to minute ttl: this.user.getTtl(1000*60) // scale to minute
}) })
const page = this.pages[0] // only get posts from first page const page = this.pages[0] // only get posts from first page
for (const item of page) { await Promise.all(page.map(item =>
feed.item(item.getFeedData()) item.fetchFeedData().then(feedData => feed.item(feedData))
} ))
return feed return feed
} }
} }

View File

@ -9,7 +9,8 @@ require("../testimports")(collectors, TimelineChild, TimelineBaseMethods)
const rssDescriptionTemplate = compile(` const rssDescriptionTemplate = compile(`
p(style='white-space: pre-line')= caption p(style='white-space: pre-line')= caption
img(alt=alt src=src) each child in children
img(alt=child.alt src=child.src width=child.width height=child.height)
`) `)
class TimelineEntry extends TimelineBaseMethods { class TimelineEntry extends TimelineBaseMethods {
@ -198,13 +199,22 @@ class TimelineEntry extends TimelineBaseMethods {
} }
} }
getFeedData() { async fetchFeedData() {
const children = await this.fetchChildren()
return { return {
title: this.getCaptionIntroduction() || `New post from @${this.getBasicOwner().username}`, title: this.getCaptionIntroduction() || `New post from @${this.getBasicOwner().username}`,
description: rssDescriptionTemplate({src: `${config.website_origin}${this.getDisplayUrlP()}`, alt: this.getAlt(), caption: this.getCaption()}), description: rssDescriptionTemplate({
caption: this.getCaption(),
children: children.map(child => ({
src: `${config.website_origin}${child.getDisplayUrlP()}`,
alt: child.getAlt(),
width: child.data.dimensions.width,
height: child.data.dimensions.height
}))
}),
author: this.data.owner.username, author: this.data.owner.username,
url: `${config.website_origin}/p/${this.data.shortcode}`, url: `${config.website_origin}/p/${this.data.shortcode}`,
guid: `${config.website_origin}/p/${this.data.shortcode}`, guid: `${config.website_origin}/p/${this.data.shortcode}`, // Is it wise to keep the origin in here? The same post would have a different ID from different servers.
date: new Date(this.data.taken_at_timestamp*1000) date: new Date(this.data.taken_at_timestamp*1000)
/* /*
Readers should display the description as HTML rather than using the media enclosure. Readers should display the description as HTML rather than using the media enclosure.

View File

@ -5,11 +5,12 @@ const {render} = require("pinski/plugins")
module.exports = [ module.exports = [
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: async ({url, fill}) => { {route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: async ({url, fill}) => {
const user = await fetchUser(fill[0]) const user = await fetchUser(fill[0])
const content = user.timeline.getFeed().xml() const content = await user.timeline.fetchFeed()
const xml = content.xml()
return { return {
statusCode: 200, statusCode: 200,
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed
content content: xml
} }
}} }}
] ]