diff --git a/src/index.ts b/src/index.ts index b34e20c..5ba660e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -299,6 +299,85 @@ export default function killTheNewsletter( ); }); + webApplication.get<{ feedReference: string }, HTML, {}, {}, {}>( + "/feeds/:feedReference.xml", + (req, res, next) => { + const feed = database.get<{ + id: number; + updatedAt: string; + title: string; + }>( + sql`SELECT "id", "updatedAt", "title" FROM "feeds" WHERE "reference" = ${req.params.feedReference}` + ); + if (feed === undefined) return next(); + const entries = database.all<{ + createdAt: string; + reference: string; + title: string; + author: string; + content: string; + }>( + sql` + SELECT "createdAt", "reference", "title", "author", "content" + FROM "entries" + WHERE "feed" = ${feed.id} + ` + ); + res + .contentType("application/atom+xml") + .header("X-Robots-Tag", "noindex") + .send( + html` + + + + + urn:kill-the-newsletter:${req.params.feedReference} + ${feed.title} + Kill the Newsletter! Inbox: + ${req.params.feedReference}@${webApplication.get("email host")} + → + ${webApplication.get("url")}/feeds/${req.params + .feedReference}.xml + ${new Date(feed.updatedAt).toISOString()} + Kill the Newsletter! + $${entries.map( + (entry) => html` + + urn:kill-the-newsletter:${entry.reference} + ${entry.title} + ${entry.author} + ${new Date(entry.createdAt).toISOString()} + + ${entry.content} + + ` + )} + + `.trim() + ); + } + ); + const emailApplication = new SMTPServer(); function newReference(): string { @@ -423,52 +502,6 @@ export const emailServer = new SMTPServer({ }, }).listen(EMAIL_PORT); -function feed(identifier: string, name: string, initialEntry: string): string { - return html` - - - - - ${urn(identifier)} - ${name} - Kill the Newsletter! Inbox: ${feedEmail(identifier)} → - ${feedURL(identifier)} - ${now()} - Kill the Newsletter! - ${initialEntry} - - `.trim(); -} - -function entry( - feedIdentifier: string, - entryIdentifier: string, - title: string, - author: string, - content: string -): string { - return html` - - ${urn(entryIdentifier)} - ${title} - ${author} - ${now()} - - ${content} - - `.trim(); -} - function alternatePath( feedIdentifier: string, entryIdentifier: string