From 2d931962b74fe06c1bfbc2454fa166d24e8e2f59 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 1 Jul 2017 14:11:52 +0200 Subject: feat: Add date to posts --- src/responders.js | 27 ++++++++++++++++++++++----- src/templates/home.html | 1 + src/templates/post.html | 1 + src/templates/taxon.html | 1 + test/app.test.js | 23 +++++++++++++++++++++++ test/domain/posts.test.js | 1 + test/testsite/posts/testfile.md | 1 + 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 @@
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 @@