about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/responders.js66
-rw-r--r--src/templates/layout.html2
-rw-r--r--test/app.test.js2
3 files changed, 42 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"/>
diff --git a/test/app.test.js b/test/app.test.js
index 8507c41..4c90881 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -18,6 +18,7 @@ test("homepage", t => {
   return request(app.listen())
     .get("/")
     .expect(200)
+    .expect(/^<!DOCTYPE html>/)
     .then(parseResponse)
     .then($ => {
       t.is($("head > title").text(), config.site.title);
@@ -30,6 +31,7 @@ test("post", t => {
   return request(app.listen())
     .get("/post/testfile")
     .expect(200)
+    .expect(/^<!DOCTYPE html>/)
     .then(parseResponse)
     .then($ => {
       t.is($("article h1").text(), "This is a test");