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
import { dataToRSS } from "https://esm.town/v/stevekrouse/dataToRSS";
import { readwiseReaderDocumentList } from "https://esm.town/v/zerovox/readwiseReaderDocumentList";
export async function readwiseReaderReadItemsRss() {
// Get all of a user's archived documents
const archivedData = await readwiseReaderDocumentList(Deno.env.get("readwiseReaderApiToken"), undefined, "archive");
// Later, if you want to get new documents updated after some date, do this:
// const docsAfterDate = new Date(Date.now() - 24 * 60 * 60 * 1000); // use your own stored date
// const newData = await fetchDocumentListApi(docsAfterDate.toISOString());
return new Response(dataToRSS(
archivedData.map((blog) => ({
title: escapeXml(blog.title + " - " + blog.author),
link: escapeXml(blog.source_url),
pubDate: new Date(blog.published_date),
description: escapeXml(blog.summary),
})),
{
title: "Tim's Read Items",
link: "https://zerovox-readwisereaderreaditemsrss.web.val.run",
rssLink: "https://zerovox-readwisereaderreaditemsrss.web.val.run",
},
));
}
function escapeXml(unsafe) {
return unsafe.replace(/[<>&'"]/g, function(c) {
switch (c) {
case "<":
return "&lt;";
case ">":
return "&gt;";
case "&":
return "&amp;";
case "'":
return "&apos;";
case "\"":
return "&quot;";
}
});
}