From c8926b8fa199d7d825318b78154f61f8d62e2554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=AB=20=E3=82=A6=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=96?= Date: Fri, 13 Jul 2018 16:58:24 -0500 Subject: [PATCH] Refactoring and cleanup --- client.js | 12 ++--- views/components/html.js | 16 ++---- views/components/layout.js | 15 +++--- views/pages/_404.js | 25 --------- views/pages/_error.js | 26 --------- views/pages/error.js | 29 ++++++++++ views/pages/home.js | 11 +--- views/pages/page.js | 10 +--- views/pages/resources.js | 11 +--- views/partials/ecosystem-scripts.js | 21 +++++--- views/partials/ecosystem.js | 2 +- views/partials/edit-link.js | 12 ++--- views/partials/email-subscribe.js | 32 +++++------ views/partials/footer.js | 11 +--- views/partials/head.js | 82 +++++++++++++---------------- views/partials/mission-statement.js | 18 ++----- views/partials/navigation.js | 43 +++++---------- views/partials/noscript.js | 25 --------- views/show.js | 33 ------------ 19 files changed, 137 insertions(+), 297 deletions(-) delete mode 100755 views/pages/_404.js delete mode 100755 views/pages/_error.js create mode 100755 views/pages/error.js delete mode 100755 views/partials/noscript.js delete mode 100755 views/show.js diff --git a/client.js b/client.js index e2c9d14..e351bf1 100755 --- a/client.js +++ b/client.js @@ -16,13 +16,12 @@ const ssr = require("choo-ssr"); const head = require("./views/partials/head"); const html = require("./views/components/html"); const layout = require("./views/components/layout"); -const noscript = require("./views/partials/noscript"); // P R O G R A M -function main () { +function main() { const app = async(choo()); app.use(ssr()); @@ -39,21 +38,16 @@ function main () { ssr.body( async.catch( layout(content), - require("./views/pages/_error")(app) + require("./views/pages/error")(app) ), - noscript(), - ssr.state(), + ssr.state() ) )); app.route("/", page(require("./views/pages/home")(app))); - // app.route("/github-feed", page(require("./views/pages/github-feed")(app))); app.route("/resources", page(require("./views/pages/resources")(app))); app.route("/*", page(require("./views/pages/page")(app))); - // app.route("/:page", page(require("./views/show")(app))); - // app.route("*", page(require("./views/pages/_404")(app))); - return app; } diff --git a/views/components/html.js b/views/components/html.js index 88eefe7..c54c31d 100755 --- a/views/components/html.js +++ b/views/components/html.js @@ -4,18 +4,18 @@ // P A C K A G E -const h = require("choo-async/html"); +const html = require("choo-async/html"); -// P R O G R A M +// E X P O R T -function html(head, body) { +module.exports = exports = (head, body) => { return (state, emit) => { const bodyPromise = Promise.resolve(body(state, emit)); const headPromise = bodyPromise.then(() => head(state, emit)); // resolve `head` once `body` is resolved - return h` + return html` ${headPromise} @@ -23,10 +23,4 @@ function html(head, body) { `; }; -} - - - -// E X P O R T - -module.exports = exports = html; +}; diff --git a/views/components/layout.js b/views/components/layout.js index 6194969..a01beba 100755 --- a/views/components/layout.js +++ b/views/components/layout.js @@ -13,18 +13,17 @@ const navigation = require("../partials/navigation"); -// P R O G R A M +// E X P O R T -const layout = children => (state, emit) => html` +module.exports = exports = children => (state, emit) => html`
+ + ${navigation(state, emit)} ${children(state, emit)} ${footer(state, emit)}
`; - - - -// E X P O R T - -module.exports = exports = layout; diff --git a/views/pages/_404.js b/views/pages/_404.js deleted file mode 100755 index 002f7dc..0000000 --- a/views/pages/_404.js +++ /dev/null @@ -1,25 +0,0 @@ -"use strict"; - - - -// P A C K A G E - -const html = require("choo-async/html"); - - - -// P R O G R A M - -// eslint-disable-next-line -const missing = () => async (state, emit) => html` -
-

404

-

This page does not exist

-
-`; - - - -// E X P O R T - -module.exports = exports = missing; diff --git a/views/pages/_error.js b/views/pages/_error.js deleted file mode 100755 index 99fb36d..0000000 --- a/views/pages/_error.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; - - - -// P A C K A G E - -const html = require("choo-async/html"); - - - -// P R O G R A M - -function error () { - return err => () => html` -
-

An error has occured

-
${err.stack}
-
- `; -} - - - -// E X P O R T - -module.exports = exports = error; diff --git a/views/pages/error.js b/views/pages/error.js new file mode 100755 index 0000000..fa33898 --- /dev/null +++ b/views/pages/error.js @@ -0,0 +1,29 @@ +"use strict"; + + + +// P A C K A G E + +const html = require("choo-async/html"); + + + +// E X P O R T + +module.exports = exports = err => html` +
+ + +
+
+
${err.stack}
+
+
+
+`; diff --git a/views/pages/home.js b/views/pages/home.js index ec849a7..141ea94 100755 --- a/views/pages/home.js +++ b/views/pages/home.js @@ -8,10 +8,9 @@ const html = require("choo-async/html"); -// P R O G R A M +// E X P O R T -// eslint-disable-next-line -const home = () => async (state, emit) => html` +module.exports = exports = () => async () => html`
@@ -121,9 +120,3 @@ const home = () => async (state, emit) => html` document.getElementsByTagName("body")[0].classList.add("home"); // TODO: make this happen in components/layout `; - - - -// E X P O R T - -module.exports = exports = home; diff --git a/views/pages/page.js b/views/pages/page.js index caad85c..b12f964 100644 --- a/views/pages/page.js +++ b/views/pages/page.js @@ -30,9 +30,9 @@ const raw = require("nanohtml/raw"); -// P R O G R A M +// E X P O R T -const page = () => async (state, emit) => { // eslint-disable-line +module.exports = exports = () => async state => { const path = state.params.wildcard; if (!fs.existsSync(`./documents/${path}.md`)) { @@ -110,9 +110,3 @@ function partialFinder(markdownBody) { return dedent(markdownBody); // partials get rendered as code snippets w/o `dedent` } - - - -// E X P O R T - -module.exports = exports = page; diff --git a/views/pages/resources.js b/views/pages/resources.js index 49b0ec6..ee39404 100644 --- a/views/pages/resources.js +++ b/views/pages/resources.js @@ -8,10 +8,9 @@ const html = require("choo-async/html"); -// P R O G R A M +// E X P O R T -// eslint-disable-next-line -const resources = () => async (state, emit) => html` +module.exports = exports = () => async () => html`