"use strict"; const fs = require("fs"); 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"); function getTemplateIndent(re, template) { return re.exec(getTemplate(template))[1].length; } const findMain = /^(\s+)
({ 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), "body > header .p-name": config.site.author.name, "body > header .u-photo": { alt: config.site.author.name, src: config.site.author.photo }, "body > main": pageElement.outerHTML }).outerHTML.trim(); } module.exports = { baseIndentLevel, postIndentLevel, indentForTemplate, home(ctx, config, posts) { ctx.type = "html"; ctx.body = layout( config, null, hyperfast(templates.home, { ".post": posts.map(renderPostListItem(ctx)) }) ); }, post(ctx, config, post) { ctx.type = "html"; ctx.body = layout( 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 } }) ); }, taxon(ctx, config, term, value, taxonItems) { ctx.type = "html"; ctx.body = layout( config, Case.title(value), hyperfast(templates.taxon, { ".post": taxonItems.map(renderPostListItem(ctx)) }) ); } };