diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/responders.js | 66 | ||||
-rw-r--r-- | src/templates/layout.html | 2 |
2 files changed, 40 insertions, 28 deletions
diff --git a/src/responders.js b/src/responders.js index a03533d..0bd841f 100644 --- a/src/responders.js +++ b/src/responders.js @@ -4,6 +4,7 @@ const h = require("highland"); const fs = require("fs"); const rheo = require("rheo"); const indent = require("indent-string"); +const PassThrough = require("stream").PassThrough; const toLines = string => string.split("\n").map((s, i, arr) => (i === arr.length - 1 ? s : s + "\n")); @@ -27,6 +28,10 @@ function templateReader(template, indentLevel) { return () => h(content); } +function prependDoctype(stream) { + return h(["<!DOCTYPE html>"]).concat(stream).pipe(new PassThrough()); +} + const templates = { layout: templateReader("layout"), home: templateReader("home", baseIndentLevel), @@ -63,40 +68,47 @@ module.exports = { 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))); - }) - .pipe(setTitle(config.site.title)) - .render(); + + ctx.body = prependDoctype( + templates + .layout() + .pipe(rheo()) + .outer("main", showPage("home")) + .inner(".posts", function(postsTemplate) { + return postsStream.pipe(postsTemplate.map(renderPostListItem(ctx))); + }) + .pipe(setTitle(config.site.title)) + .render() + ); }, 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(); + ctx.body = prependDoctype( + 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() + ); }, 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))); - }) - .pipe(setTitle(config.site.title)) - .render(); + ctx.body = prependDoctype( + 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))); + }) + .pipe(setTitle(config.site.title)) + .render() + ); } }; diff --git a/src/templates/layout.html b/src/templates/layout.html index 733bbc4..994ce02 100644 --- a/src/templates/layout.html +++ b/src/templates/layout.html @@ -1,4 +1,4 @@ -<!doctype html> +<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> |