From 2724333412fd4429a574b942596a413108bd345b Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Mon, 10 Aug 2020 00:30:12 +0100 Subject: [PATCH] Add html tagged template literal --- index.ts | 141 +++++++++++++++++++++++++++++++--------------- package-lock.json | 5 ++ package.json | 1 + 3 files changed, 101 insertions(+), 46 deletions(-) diff --git a/index.ts b/index.ts index 14fc9cc..230cdd9 100644 --- a/index.ts +++ b/index.ts @@ -8,6 +8,7 @@ import { JSDOM } from "jsdom"; import { promises as fs } from "fs"; import writeFileAtomic from "write-file-atomic"; import cryptoRandomString from "crypto-random-string"; +import html from "tagged-template-noop"; export const WEB_PORT = process.env.WEB_PORT ?? 8000; export const EMAIL_PORT = process.env.EMAIL_PORT ?? 2525; @@ -36,7 +37,7 @@ export const webServer = express() ) ); res.send( - layout(` + layout(html`

“${H(name)}” Inbox Created

${renderedCreated} `) @@ -121,42 +122,76 @@ async function addEntryToFeed( } await writeFileAtomic( path, - `${feed.serialize()}` + html`${feed.serialize()}`.trim() ); } function layout(content: string): string { - return ` + return html` + - - - - Kill the Newsletter! - - - - - - - - -
-

Kill the Newsletter!

-

Convert email newsletters into Atom feeds

-

Convert email newsletters into Atom feeds

-
-
${content}
- - + + + + Kill the Newsletter! + + + + + + + + +
+

Kill the Newsletter!

+

Convert email newsletters into Atom feeds

+

+ Convert email newsletters into Atom feeds +

+
+
${content}
+ + - `; + `.trim(); } function newInbox(): string { - return ` + return html`

- +

@@ -164,33 +199,45 @@ function newInbox(): string { } function created(identifier: string): string { - return ` -

Sign up for the newsletter with
${feedEmail( - identifier - )}

-

Subscribe to the Atom feed at
${feedURL(identifier)}

-

Don’t share these addresses.
They contain an identifier that other people could use
to send you spam and to control your newsletter subscriptions.

+ return html` +

+ Sign up for the newsletter with
${feedEmail(identifier)} +

+

+ Subscribe to the Atom feed at
${feedURL(identifier)} +

+

+ Don’t share these addresses.
They contain an identifier that other + people could use
to send you spam and to control your newsletter + subscriptions. +

Enjoy your readings!

-

Create Another Inbox

+

+ Create Another Inbox +

`.trim(); } function feed(identifier: string, name: string): string { - return ` + return html` + - - + + ${urn(identifier)} ${name} - Kill the Newsletter! Inbox: ${feedEmail( - identifier - )} → ${feedURL(identifier)} + Kill the Newsletter! Inbox: ${feedEmail(identifier)} → + ${feedURL(identifier)} ${now()} Kill the Newsletter! - `; + `.trim(); } function entry( @@ -199,15 +246,17 @@ function entry( author: string, content: string ): string { - return ` + return html` ${urn(identifier)} ${title} ${author} ${now()} - + ${content} `.trim(); diff --git a/package-lock.json b/package-lock.json index 4d4358e..cc72cd5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7744,6 +7744,11 @@ "integrity": "sha512-gtqfvz5jUIMqWn0kkdkV4G8uiLmJckQ+z6aKy1uyE0OPU/6tStubahtZDiF0ajSRVJht+Vd4pX5DDwQLhAapww==", "optional": true }, + "tagged-template-noop": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/tagged-template-noop/-/tagged-template-noop-2.1.1.tgz", + "integrity": "sha512-diZ004cBHKVueqSr5p+/EPZhofCBRW7w7zZL71FcK8x+209BbMw77ICrP9AWXpVjPyyyIqRYYFAM4Wjk2HNWQg==" + }, "tar": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.2.tgz", diff --git a/package.json b/package.json index 1a2908d..9624cbb 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "pm2": "^4.2.3", "sanitize-xml-string": "^1.1.0", "smtp-server": "^3.6.0", + "tagged-template-noop": "^2.1.1", "ts-node": "^8.10.1", "typescript": "^3.8.3", "write-file-atomic": "^3.0.3"