diff --git a/lib.js b/lib.js index 22ace52..c762f3c 100644 --- a/lib.js +++ b/lib.js @@ -138,8 +138,11 @@ export const delayedFetch = async (url, options, courtesyWait = 5 * 1000) => { return await fetch(url, options) } +export const getCacheFilename = (source) => + source.name + '.xml' + export const getCachePath = (source, { directory }) => - Path.join(directory, source.name + '.xml') + Path.join(directory, getCacheFilename(source)) export const cacheSource = (source, cache) => write(getCachePath(source, cache), createCache(source, cache)) @@ -186,17 +189,16 @@ export const openCache = async (source, cache) => { export const buildCacheLink = source => new URL('https://' + source.hostname) -// TODO: Support atom links -// https://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html -// TODO: Add a description of some kind export const createCache = (source, cache) => `\ <?xml version="1.0" encoding="UTF-8" ?> -<rss version="2.0"> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>${source.displayName}</title> +<description>${source.description}</description> <link>${buildCacheLink(source)}</link> +<atom:link href="${new URL(getCacheFilename(source), cache.directoryUrl)}" rel="self" type="application/rss+xml" /> <pubDate>${new Date(source.latestPostDate).toUTCString()}</pubDate> <generator>rssssing</generator> ${source.posts.map(post => post.item.outerHTML.replaceAll(/\n\s*/g, '')).join('\n')} @@ -582,6 +584,7 @@ export const tumblr = { createSource(user, courtesyWait, postReducerCallback, cache) { let lowercaseUser = user.toLowerCase() let source = { + description: `Aggregate feed for @${lowercaseUser} on tumblr.com`, hostname: lowercaseUser + '.tumblr.com', pathname: 'rss', courtesyWait, @@ -621,6 +624,7 @@ export const tumblr = { export const nitter = { createSource(user, instances, courtesyWait, postReducerCallback, cache) { let source = { + description: `Aggregate feed for @${user} on twitter.com`, instances, pathname: user + '/rss', courtesyWait,