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
import { hnResultToText } from "https://esm.town/v/stevekrouse/hnResultToText";
export let hnEmail = async ({
posts,
footer,
}: {
posts: any[];
footer?: boolean; // undefined defaults to true
}) => {
let authors = Array.from(new Set(posts.map((p) => p.author))).slice(0, 3);
let subject = `[HN Follow] New from ${authors.join(", ")}`;
let postTexts = await Promise.all(
posts.map(hnResultToText)
);
let footer_ = [
"----------------------------------------",
"Email by hnfollow.com & https://val.town",
"You can unsubscribe by clearing your interval here: https://val.town/@me.intervals",
];
let text = [
postTexts.join("\n\n"),
...(footer === false ? [] : footer_),
].join("\n\n");
return { subject, text };
};