substr/feeds.ts

39 lines
1.2 KiB
TypeScript

import Article from "./models/article.ts";
import Profile from "./models/profile.ts";
import { isoDate } from "./dates.ts";
export function profileAtomFeed(profile: Profile, articles: Article[]) {
const feedId = `tag:${profile.nip05},nostr-p-${profile.pubkey}-k-30023`;
const lastUpdate = articles.sort((a, b) => b.updatedAt - a.updatedAt)[0]
?.updatedAt;
const articlesXml = articles.map((article) => {
const articleId =
`tag:${profile.nip05},nostr-d-${article.identifier}-k-30023`;
return `
<entry>
<id>${articleId}</id>
<title>${article.title}</title>
<link href="${article.url}" />
<updated>${isoDate(article.updatedAt)}</updated>
<summary>${article.summary}</summary>
<content type="html">${article.html}</content>
</entry>
`;
}).join("\n");
return `
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>${profile.name} on Nostr</title>
<id>${feedId}</id>
<updated>${isoDate(lastUpdate)}</updated>
<icon>${profile.picture}</icon>
<author>
<name>${name}</name>
</author>
${articlesXml}
</feed>
`.trim();
}