Back to packages list

Vals using rss-parser

Description from the NPM package:
A lightweight RSS parser, for Node and the browser

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.

Readme
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;
}[];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env -S deno run -A
import Parser from "npm:rss-parser";
import { formatDistance } from "npm:date-fns";
import * as sunbeam from "https://deno.land/x/sunbeam/mod.ts";
const manifest = {
title: "Hacker News",
description: "Browse Hacker News",
commands: [
{
name: "browse",
title: "Show a feed",
mode: "filter",
params: [{ name: "topic", label: "Topic", type: "text" }],
},
],
} as const satisfies sunbeam.Manifest;
if (Deno.args.length == 0) {
console.log(JSON.stringify(manifest));
Deno.exit(0);
}
const payload: sunbeam.Payload<typeof manifest> = JSON.parse(Deno.args[0]);
if (payload.command == "browse") {
const { topic } = payload.params;
const feed = await new Parser().parseURL(
`https://hnrss.org/${topic}?description=0&count=25`
);
const page: sunbeam.List = {
items: feed.items.map((item) => ({
title: item.title || "",
subtitle: item.categories?.join(", ") || "",
accessories: item.isoDate
? [
formatDistance(new Date(item.isoDate), new Date(), {
addSuffix: true,
}),
]
: [],
actions: [
{
title: "Open in browser",
type: "open",
open: {
url: item.link || "",
},
},
{
title: "Open Comments in Browser",
type: "open",
open: {
url: item.guid || "",
},
},
{
title: "Copy Link",
type: "copy",
key: "c",
copy: {
text: item.link || "",
exit: true,
},
},
],
})),
};
console.log(JSON.stringify(page));
} else {
console.error("Unknown command");
Deno.exit(1);
}
// #sunbeam
Runs every 1 hrs
Fork
1
2
3
4
5
6
7
8
9
export const scheduleExampleTwo = async (interval: Interval) => {
const { default: RssParser } = await import("npm:rss-parser");
const parser = new RssParser();
const feed = await parser.parseURL("http://feeds.bbci.co.uk/news/rss.xml");
const newItems = feed.items.filter((item) =>
new Date(item.pubDate) > interval.lastRunAt
);
return `${newItems.length} new items!`;
};

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.

Readme
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;
}[];
}
1
Next