about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2017-06-30 13:11:45 +0200
committerAlan Pearce2017-06-30 13:11:45 +0200
commit136ebe22452c0015770d9f0ac9d94d8941461816 (patch)
tree95778b14f19131ee94e7c281844cfc26d5cfbade
parent36f5609c814a361214a755ebe57633f75bc4920a (diff)
downloadhomestead-136ebe22452c0015770d9f0ac9d94d8941461816.tar.lz
homestead-136ebe22452c0015770d9f0ac9d94d8941461816.tar.zst
homestead-136ebe22452c0015770d9f0ac9d94d8941461816.zip
refactor: remove console.log
-rw-r--r--src/responders.js113
1 files changed, 57 insertions, 56 deletions
diff --git a/src/responders.js b/src/responders.js
index 824195b..a03533d 100644
--- a/src/responders.js
+++ b/src/responders.js
@@ -1,58 +1,59 @@
-'use strict'
+"use strict";
 
-const h = require('highland')
-const fs = require('fs')
-const rheo = require('rheo')
-const indent = require('indent-string')
+const h = require("highland");
+const fs = require("fs");
+const rheo = require("rheo");
+const indent = require("indent-string");
 
 const toLines = string =>
-  string.split('\n').map((s, i, arr) => (i === arr.length - 1 ? s : s + '\n'))
+  string.split("\n").map((s, i, arr) => (i === arr.length - 1 ? s : s + "\n"));
 
 const getTemplate = name =>
-  fs.readFileSync(`${__dirname}/templates/${name}.html`, 'utf8')
+  fs.readFileSync(`${__dirname}/templates/${name}.html`, "utf8");
 
-const findMain = /^(\s+)<main/m
-const baseIndentLevel = findMain.exec(getTemplate('layout'))[1].length
+const findMain = /^(\s+)<main/m;
+const baseIndentLevel = findMain.exec(getTemplate("layout"))[1].length;
 const postIndentLevel =
-  baseIndentLevel + findMain.exec(getTemplate('post'))[1].length
+  baseIndentLevel + findMain.exec(getTemplate("post"))[1].length;
 
-function indentForTemplate (text, indentLevel) {
-  return indent(text, indentLevel).slice(indentLevel).replace(/\n+$/, '')
+function indentForTemplate(text, indentLevel) {
+  return indent(text, indentLevel).slice(indentLevel).replace(/\n+$/, "");
 }
 
-function templateReader (template, indentLevel) {
-  const content = toLines(indentForTemplate(getTemplate(template), indentLevel))
-  console.log(template, content)
-  return () => h(content)
+function templateReader(template, indentLevel) {
+  const content = toLines(
+    indentForTemplate(getTemplate(template), indentLevel)
+  );
+  return () => h(content);
 }
 
 const templates = {
-  layout: templateReader('layout'),
-  home: templateReader('home', baseIndentLevel),
-  post: templateReader('post', baseIndentLevel),
-  taxon: templateReader('taxon', baseIndentLevel)
-}
+  layout: templateReader("layout"),
+  home: templateReader("home", baseIndentLevel),
+  post: templateReader("post", baseIndentLevel),
+  taxon: templateReader("taxon", baseIndentLevel)
+};
 
-function setTitle (siteTitle, pageTitle) {
-  return rheo.template(function (s) {
+function setTitle(siteTitle, pageTitle) {
+  return rheo.template(function(s) {
     return s
-      .inner('title', rheo((pageTitle ? ' &middot; ' : '') + siteTitle))
-      .inner('body header h1', rheo(siteTitle))
-  })
+      .inner("title", rheo((pageTitle ? " &middot; " : "") + siteTitle))
+      .inner("body header h1", rheo(siteTitle));
+  });
 }
 
-function renderPostListItem (ctx) {
-  return function (template, [, post]) {
+function renderPostListItem(ctx) {
+  return function(template, [, post]) {
     return template
-      .attribute('a', 'href', () => ctx.getURL('post', post.basename))
-      .inner('a', () => rheo(post.data.get('title')))
-  }
+      .attribute("a", "href", () => ctx.getURL("post", post.basename))
+      .inner("a", () => rheo(post.data.get("title")));
+  };
 }
 
-function showPage (name) {
-  return function (els) {
-    return rheo(templates[name]())
-  }
+function showPage(name) {
+  return function(els) {
+    return rheo(templates[name]());
+  };
 }
 
 module.exports = {
@@ -60,42 +61,42 @@ module.exports = {
   postIndentLevel,
   indentForTemplate,
 
-  home (ctx, config, postsStream) {
-    ctx.type = 'html'
+  home(ctx, config, postsStream) {
+    ctx.type = "html";
     ctx.body = templates
       .layout()
       .pipe(rheo())
-      .outer('main', showPage('home'))
-      .inner('.posts', function (postsTemplate) {
-        return postsStream.pipe(postsTemplate.map(renderPostListItem(ctx)))
+      .outer("main", showPage("home"))
+      .inner(".posts", function(postsTemplate) {
+        return postsStream.pipe(postsTemplate.map(renderPostListItem(ctx)));
       })
       .pipe(setTitle(config.site.title))
-      .render()
+      .render();
   },
 
-  post (ctx, config, post) {
-    ctx.type = 'html'
+  post(ctx, config, post) {
+    ctx.type = "html";
     ctx.body = templates
       .layout()
       .pipe(rheo())
-      .outer('main', showPage('post'))
-      .inner('article h1', rheo(post.data.get('title')))
-      .outer('article main', rheo(post.body))
-      .pipe(setTitle(config.site.title, post.data.get('title')))
-      .render()
+      .outer("main", showPage("post"))
+      .inner("article h1", rheo(post.data.get("title")))
+      .outer("article main", rheo(post.body))
+      .pipe(setTitle(config.site.title, post.data.get("title")))
+      .render();
   },
 
-  taxon (ctx, config, taxonItems) {
-    ctx.type = 'html'
+  taxon(ctx, config, taxonItems) {
+    ctx.type = "html";
     ctx.body = templates
       .layout()
       .pipe(rheo())
-      .outer('main', showPage('taxon'))
-      .inner('h1', rheo(config.site.title))
-      .inner('.posts', function (postsTemplate) {
-        return taxonItems.pipe(postsTemplate.map(renderPostListItem(ctx)))
+      .outer("main", showPage("taxon"))
+      .inner("h1", rheo(config.site.title))
+      .inner(".posts", function(postsTemplate) {
+        return taxonItems.pipe(postsTemplate.map(renderPostListItem(ctx)));
       })
       .pipe(setTitle(config.site.title))
-      .render()
+      .render();
   }
-}
+};