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
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!
January 1, 2024