feat: Add date to posts
1 file changed, 22 insertions(+), 5 deletions(-)
changed files
M src/responders.js โ 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,12 +44,20 @@ 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, {@@ -80,6 +96,7 @@ config, 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 }