Back

Version 12

6/19/2024
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 "'":