diff options
author | Alan Pearce | 2017-06-30 19:09:30 +0200 |
---|---|---|
committer | Alan Pearce | 2017-06-30 19:10:26 +0200 |
commit | 9937c2a51ad9944da0239ebd7f777e5d6d8233d4 (patch) | |
tree | 07ef1fba4dc75bcfc557608faccdb218078da7e4 /src | |
parent | 31f441ff32ab9f52fc80d0835bdd074554587ef6 (diff) | |
download | homestead-9937c2a51ad9944da0239ebd7f777e5d6d8233d4.tar.lz homestead-9937c2a51ad9944da0239ebd7f777e5d6d8233d4.tar.zst homestead-9937c2a51ad9944da0239ebd7f777e5d6d8233d4.zip |
fix: Add missing doctype via stream concat
rheo appears to be stripping it out
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"/> |