Skip to content

RSS

Val Town can both parse and generate RSS feeds for blogs and other updated sources.

Polling RSS

You would run this example in val town as a Scheduled val that ran on a regular interval, and it would check a blog’s feed every 15 minutes.

Polling example
import { email } from "https://esm.town/v/std/email?v=9";
import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems";
import { rssFeeds } from "https://esm.town/v/stevekrouse/rssFeeds";
export async function pollRSSFeeds({ lastRunAt }: Interval) {
return Promise.all(
Object.entries(rssFeeds).map(async ([name, url]) => {
let items = await newRSSItems({
url,
lastRunAt,
});
if (items.length)
await email({
text: JSON.stringify(items, null, 2),
subject: `New from ${name} RSS`,
});
return { name, items };
}),
);
}

Creating RSS

Creating example
import { dataToRSS } from "https://esm.town/v/stevekrouse/dataToRSS";
import { valTownBlogJSON } from "https://esm.town/v/stevekrouse/valTownBlogJSON";
export async function valTownBlogRSS() {
const json = await valTownBlogJSON();
return dataToRSS(
json.map((blog) => ({
title: blog.title,
link: blog.url,
pubDate: blog.date,
})),
{
title: "Val Town Blog",
link: "https://blog.val.town",
rssLink: "https://stevekrouse-blogrss.web.val.run/",
},
);
}