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
export default async function harpers() {
const { default: { load } } = await import("https://cdn.jsdelivr.net/npm/cheerio@1.0.0-rc.12/+esm");
const { default: { sentences } } = await import("https://cdn.jsdelivr.net/npm/sbd@1.0.19/+esm");
const continuations = "Who In By Of That".split(" ");
async function request(url) {
console.log(url);
const res = await fetch(url);
return load(await res.text());
}
const results = await Promise.all([
request("https://harpers.org/sections/findings/")
.then(($) => request($(".card a").attr("href")))
.then(($) => sentences($(".wysiwyg-content > p").text())),
request("https://harpers.org/harpers-index/")
.then(($) =>
$(".index-statement")
.map((_, s) =>
$("> p", s).text()
+ $("> span", s).text().trim().replace(/\s+/g, " ")
)
.get()
)
.then((lines) =>
lines.reduce((lines, line) => {
if (lines.length === 0)
lines.push(line);
else if (continuations.some((c) => line.startsWith(c)))
lines[lines.length - 1] = lines[lines.length - 1] + ", " + line;
else
lines.push(line);
return lines;
}, [])
),
]);
return new Response(results.flat().join("\n"));
}