From 9937c2a51ad9944da0239ebd7f777e5d6d8233d4 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 30 Jun 2017 19:09:30 +0200 Subject: fix: Add missing doctype via stream concat rheo appears to be stripping it out --- src/responders.js | 66 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'src/responders.js') 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([""]).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() + ); } }; -- cgit 1.4.1