import { dataToRSS } from "https://esm.town/v/stevekrouse/dataToRSS";
import { readwiseReaderDocumentList } from "https://esm.town/v/zerovox/readwiseReaderDocumentList";
export async function readwiseReaderReadItemsRss() {
const archivedData = await readwiseReaderDocumentList(Deno.env.get("readwiseReaderApiToken"), undefined, "archive");
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 "<";
case ">":
return ">";
case "&":
return "&";
case "'":
return "'";
case "\"":
return """;
}
});
}