about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/responders.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/responders.js b/src/responders.js
index 9633e15..e6ec5d0 100644
--- a/src/responders.js
+++ b/src/responders.js
@@ -7,11 +7,14 @@ const indent = require("indent-string");
 const getTemplate = name =>
   fs.readFileSync(`${__dirname}/templates/${name}.html`, "utf8");
 
+function getTemplateIndent(re, template) {
+  return re.exec(getTemplate(template))[1].length;
+}
 const findMain = /^(\s+)<main/m;
-const baseIndentLevel = findMain.exec(getTemplate("layout"))[1].length;
+const baseIndentLevel = getTemplateIndent(findMain, "layout");
+const findPostContent = /^(\s+)<div class="post-content/m;
 const postIndentLevel =
-  baseIndentLevel +
-  /^(\s+)<div class="post-content/m.exec(getTemplate("post"))[1].length;
+  baseIndentLevel + getTemplateIndent(findPostContent, "post");
 
 function indentForTemplate(text, indentLevel) {
   return indent(text, indentLevel).slice(indentLevel).replace(/\n+$/, "");