diff options
author | Alan Pearce | 2017-07-01 13:02:11 +0200 |
---|---|---|
committer | Alan Pearce | 2017-07-01 13:02:11 +0200 |
commit | ab46e976f5bd9414d95a5f3a9441481d10453710 (patch) | |
tree | 6242c4868334c1f73ca76dd67b1848636df5d950 /src | |
parent | fb7e421b9efea0a96adcf30d30cc2d318980d928 (diff) | |
download | homestead-ab46e976f5bd9414d95a5f3a9441481d10453710.tar.lz homestead-ab46e976f5bd9414d95a5f3a9441481d10453710.tar.zst homestead-ab46e976f5bd9414d95a5f3a9441481d10453710.zip |
refactor: Extract logic to get template indent level
Diffstat (limited to 'src')
-rw-r--r-- | src/responders.js | 9 |
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+$/, ""); |