Readme

This is an RSS parser val, similar to @stevekrouse.fetchRSS, but uses an NPM parsing library so it can support multiple RSS feed types easily.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { fetch } from "https://esm.town/v/std/fetch";
// This supports more RSS types than @stevekrouse.fetchRSS
export async function fetchRss(url: string, lastRunDate?: string | number) {
let Parser = await import("npm:rss-parser");
let parser = new Parser.default();
let response = await fetch(url);
let data = await response.text();
let { items } = await parser.parseString(data);
if (lastRunDate) {
items = items.filter((i) => new Date(i.isoDate) >= new Date(lastRunDate));
}
return items as {
title: string;
link: string;
author: string;
pubDate: string;
isoDate: string;
id: string;
content: string;
contentSnippet: string;
}[];
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 11, 2024