summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2017-07-01 14:11:52 +0200
committerAlan Pearce2017-07-01 14:12:07 +0200
commit2d931962b74fe06c1bfbc2454fa166d24e8e2f59 (patch)
tree028972fae8fe6d7274ad58ccae5ac8bcc1f93d8e /src
parentb0b4517c1329595f9525bcc9e9e176dc5b43f575 (diff)
downloadhomestead-2d931962b74fe06c1bfbc2454fa166d24e8e2f59.tar.lz
homestead-2d931962b74fe06c1bfbc2454fa166d24e8e2f59.tar.zst
homestead-2d931962b74fe06c1bfbc2454fa166d24e8e2f59.zip
feat: Add date to posts
Diffstat (limited to 'src')
-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
4 files changed, 25 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>