From 319838f7b3f65e2e58238883f39cdc75f37ad5e3 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Wed, 10 Mar 2021 11:05:04 +0000 Subject: [PATCH] --- public/styles.css | 31 ------ src/index.ts | 245 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 196 insertions(+), 80 deletions(-) delete mode 100644 public/styles.css diff --git a/public/styles.css b/public/styles.css deleted file mode 100644 index 1aa2d9a..0000000 --- a/public/styles.css +++ /dev/null @@ -1,31 +0,0 @@ -body { - line-height: 1.5; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, - Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; - text-align: center; - padding: 0 1em; - margin: 2em 0; -} - -a { - color: black; - text-decoration: none; -} - -code { - font-family: Menlo, Monaco, "Courier New", monospace; -} - -h1 { - font-size: 1.5em; -} - -footer { - font-size: 0.875em; -} - -input { - border: 1px solid #dfdfdf; - border-radius: 3px; - padding: 0.25em; -} diff --git a/src/index.ts b/src/index.ts index 1547328..daf2229 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,8 @@ import mailparser from "mailparser"; import escapeStringRegexp from "escape-string-regexp"; import fs from "fs-extra"; import cryptoRandomString from "crypto-random-string"; +import { html, HTML } from "@leafac/html"; +import { css, process as processCSS } from "@leafac/css"; const VERSION = require("../package.json").version; @@ -16,7 +18,189 @@ export default function killTheNewsletter( webApplication.set("url", "http://localhost:4000"); webApplication.set("email port", 2525); webApplication.set("email host", "localhost"); - webApplication.set("administrator", "kill-the-newsletter@leafac.com"); + webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com"); + + webApplication.use(express.static(path.join(__dirname, "../public"))); + webApplication.use(express.urlencoded({ extended: true })); + + const logo = fs.readFileSync(path.join(__dirname, "../public/logo.svg")); + + function layout(body: HTML): HTML { + return processCSS(html` + + + + + + Kill the Newsletter! + + +
+

+ Kill the Newsletter! +

+

Convert email newsletters into Atom feeds

+

+ $${logo} +

+
+
$${body}
+ + + + `); + } + + webApplication.get<{}, HTML, {}, {}, {}>("/", (req, res) => { + res.send( + layout(html` +
+

+ +

+

+
+ `) + ); + }); const emailApplication = new SMTPServer(); @@ -25,13 +209,10 @@ export default function killTheNewsletter( if (require.main === module) { console.log(`Kill the Newsletter!/${VERSION}`); - const configurationFile = path.resolve( process.argv[2] ?? path.join(process.cwd(), "configuration.js") ); - require(configurationFile)(require); - console.log(`Configuration file loaded from ‘${configurationFile}’.`); } @@ -41,8 +222,6 @@ export const webServer = express() res.header("X-Robots-Tag", "noindex"); next(); }) - .use(express.static("static")) - .use(express.urlencoded({ extended: true })) .get("/", (req, res) => res.send(layout(newInbox()))) .post("/", async (req, res, next) => { try { @@ -103,7 +282,7 @@ export const webServer = express() } } ) - .listen(WEB_PORT, () => console.log(`Server started: ${BASE_URL}`)); + .listen(WEB_PORT, () => console.log(`Server started: ${webApplication.get("url")}`)); export const emailServer = new SMTPServer({ disabledCommands: ["AUTH", "STARTTLS"], @@ -189,40 +368,21 @@ function layout(content: string): string { rel="icon" type="image/png" sizes="32x32" - href="${BASE_URL}/favicon-32x32.png" + href="${webApplication.get("url")}/favicon-32x32.png" /> - - + + -
-

Kill the Newsletter!

-

Convert email newsletters into Atom feeds

-

- Convert email newsletters into Atom feeds -

-
${content}
- - - + + `.trim(); @@ -230,19 +390,6 @@ function layout(content: string): string { function newInbox(): string { return html` -
-

- - -

-
`; } @@ -265,7 +412,7 @@ function created(identifier: string): string {

Enjoy your readings!

- Create Another Inbox + Create Another Inbox

`.trim(); } @@ -279,7 +426,7 @@ function feed(identifier: string, name: string, initialEntry: string): string { type="application/atom+xml" href="${feedURL(identifier)}" /> - + ${urn(identifier)} ${name}