about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/responders.js27
-rw-r--r--src/templates/home.html1
-rw-r--r--src/templates/post.html1
-rw-r--r--src/templates/taxon.html1
-rw-r--r--test/app.test.js23
-rw-r--r--test/domain/posts.test.js1
-rw-r--r--test/testsite/posts/testfile.md1
7 files changed, 50 insertions, 5 deletions
diff --git a/src/responders.js b/src/responders.js
index 70f7f90..4049ebf 100644
--- a/src/responders.js
+++ b/src/responders.js
@@ -5,6 +5,14 @@ const Case = require("case");
 const hyperfast = require("hyperfast");
 const indent = require("indent-string");
 
+const postDateFormatter = new Intl.DateTimeFormat("en-GB", {
+  hour12: false,
+  weekday: "long",
+  year: "numeric",
+  month: "long",
+  day: "numeric"
+});
+
 const getTemplate = name =>
   fs.readFileSync(`${__dirname}/templates/${name}.html`, "utf8");
 
@@ -36,13 +44,21 @@ function title(siteTitle, pageTitle) {
   return pageTitle ? `${pageTitle} ยท ${siteTitle}` : siteTitle;
 }
 
-const renderPostListItem = ctx => post => ({
-  a: {
-    href: ctx.getURL("post", post.basename),
-    _text: post.data.get("title")
-  }
+const makeTime = date => ({
+  datetime: date.toISOString(),
+  _text: postDateFormatter.format(date)
 });
 
+const renderPostListItem = ctx => post => {
+  return {
+    time: makeTime(post.data.get("date")),
+    a: {
+      href: ctx.getURL("post", post.basename),
+      _text: post.data.get("title")
+    }
+  };
+};
+
 function layout(config, pageTitle, pageElement) {
   return hyperfast(templates.layout, {
     title: title(config.site.author.name, pageTitle),
@@ -80,6 +96,7 @@ module.exports = {
       post.data.get("title"),
       hyperfast(templates.post, {
         "article h1": post.data.get("title"),
+        "article time": makeTime(post.data.get("date")),
         "article .post-content": {
           _html: post.body
         }
diff --git a/src/templates/home.html b/src/templates/home.html
index 97ac89a..a3597a1 100644
--- a/src/templates/home.html
+++ b/src/templates/home.html
@@ -1,5 +1,6 @@
 <ul class="posts">
   <li class="post">
     <a href="/">Test post please ignore</a>
+    <time></time>
   </li>
 </ul>
diff --git a/src/templates/post.html b/src/templates/post.html
index 384e6bb..27bcdc3 100644
--- a/src/templates/post.html
+++ b/src/templates/post.html
@@ -1,5 +1,6 @@
 <article>
   <h1>post title</h1>
+  <time></time>
   <div class="post-content">
     Fringilla ut morbi tincidunt augue interdum velit euismod!
     Interdum velit laoreet id donec ultrices tincidunt arcu, non
diff --git a/src/templates/taxon.html b/src/templates/taxon.html
index 97ac89a..a3597a1 100644
--- a/src/templates/taxon.html
+++ b/src/templates/taxon.html
@@ -1,5 +1,6 @@
 <ul class="posts">
   <li class="post">
     <a href="/">Test post please ignore</a>
+    <time></time>
   </li>
 </ul>
diff --git a/test/app.test.js b/test/app.test.js
index f673247..6810089 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -39,6 +39,15 @@ test("homepage", t => {
         "/post/testfile",
         "first post url"
       );
+      t.is(
+        $(".post:first-of-type time").text(),
+        "Sunday, January 1, 2017",
+        "first post date"
+      );
+      t.is(
+        $(".post:first-of-type time").attr("datetime"),
+        new Date("2017-01-01").toISOString()
+      );
       return $;
     })
     .then(toMicroformatsOptions)
@@ -84,6 +93,15 @@ test("post", t => {
         "article header is post title"
       );
       t.is(
+        $("article time").text(),
+        "Sunday, January 1, 2017",
+        "first post date"
+      );
+      t.is(
+        $("article time").attr("datetime"),
+        new Date("2017-01-01").toISOString()
+      );
+      t.is(
         $("article p").text(),
         `Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat \
 velit, scelerisque in dictum non, consectetur a erat nam at lectus \
@@ -124,6 +142,11 @@ test("tags", t => {
         "/post/testfile",
         "post url"
       );
+      t.is(
+        $(".post:first-of-type time").text(),
+        "Sunday, January 1, 2017",
+        "first post date"
+      );
     });
 });
 
diff --git a/test/domain/posts.test.js b/test/domain/posts.test.js
index c433ce5..cc236c7 100644
--- a/test/domain/posts.test.js
+++ b/test/domain/posts.test.js
@@ -14,6 +14,7 @@ test("get", t => {
     Object.entries({
       title: "This is a test",
       description: "Test file",
+      date: new Date("2017-01-01T00:00:00Z"),
       tags: ["a", "b"]
     })
   );
diff --git a/test/testsite/posts/testfile.md b/test/testsite/posts/testfile.md
index 65f2122..84d8ed1 100644
--- a/test/testsite/posts/testfile.md
+++ b/test/testsite/posts/testfile.md
@@ -1,6 +1,7 @@
 +++
 Title = "This is a test"
 Description = "Test file"
+Date = 2017-01-01T02:00:00+02:00
 Tags = ["a", "b"]
 +++
 Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat