diff --git a/src/components.tsx b/src/components.tsx index 8150a15..67c06b9 100644 --- a/src/components.tsx +++ b/src/components.tsx @@ -1,4 +1,11 @@ import React from "react"; +import ReactDOMServer from "react-dom/server"; +import cryptoRandomString from "crypto-random-string"; + +export type Inbox = { + name: string; + token: string; +}; export class Layout extends React.Component { render() { @@ -81,21 +88,23 @@ export class Form extends React.Component { } } -export class Created extends React.Component<{ name: string; token: string }> { +export class Created extends React.Component<{ inbox: Inbox }> { render() { + const { name, token } = this.props.inbox; return ( <> -
Sign up for the newsletter with
- {this.props.token}@kill-the-newsletter.com
+ {token}@kill-the-newsletter.com
Subscribe to the Atom feed at
- https://www.kill-the-newsletter.com/feeds/{this.props.token}.xml
+ https://www.kill-the-newsletter.com/feeds/{token}
+ .xml
@@ -115,3 +124,80 @@ export class Created extends React.Component<{ name: string; token: string }> {
);
}
}
+
+// https://validator.w3.org/feed/docs/atom.html
+
+export function Feed(inbox: Inbox): object {
+ const { name, token } = inbox;
+ return {
+ feed: {
+ $: { xmlns: "http://www.w3.org/2005/Atom" },
+ link: [
+ {
+ $: {
+ rel: "self",
+ type: "application/atom+xml",
+ href: `https://www.kill-the-newsletter.com/feeds/${token}.xml`
+ }
+ },
+ {
+ $: {
+ rel: "alternate",
+ type: "text/html",
+ href: "https://www.kill-the-newsletter.com/"
+ }
+ }
+ ],
+ id: id(token),
+ title: name,
+ subtitle: `Kill the Newsletter! Inbox “${token}@kill-the-newsletter.com”`,
+ updated: now(),
+ ...Entry({
+ title: `“#${name}” Inbox Created`,
+ author: "Kill the Newsletter!",
+ content: ReactDOMServer.renderToStaticMarkup(
+