From b7bf162e6c3bc834097e65936704e3eac59eb4bd Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 2 Jul 2017 15:30:20 +0200 Subject: feat: Use microformats classes Add snapshot-based tests to ensure microformats data can be extracted correctly. --- src/responders.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src/responders.js') diff --git a/src/responders.js b/src/responders.js index 4049ebf..867310a 100644 --- a/src/responders.js +++ b/src/responders.js @@ -21,7 +21,7 @@ function getTemplateIndent(re, template) { } const findMain = /^(\s+)
({ _text: postDateFormatter.format(date) }); -const renderPostListItem = ctx => post => { +const renderPost = ctx => post => { return { - time: makeTime(post.data.get("date")), - a: { - href: ctx.getURL("post", post.basename), - _text: post.data.get("title") + ".dt-published": makeTime(post.data.get("date")), + ".p-name": post.data.get("title"), + ".u-url": { + href: ctx.getURL("post", post.basename) + }, + ".e-content": { + _html: post.body } }; }; @@ -62,8 +65,8 @@ const renderPostListItem = ctx => post => { 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": { + ".h-card .p-name": config.site.author.name, + ".h-card .u-photo": { alt: config.site.author.name, src: config.site.author.photo }, @@ -83,7 +86,7 @@ module.exports = { config, null, hyperfast(templates.home, { - ".post": posts.map(renderPostListItem(ctx)) + ".h-entry": posts.map(renderPost(ctx)) }) ); }, @@ -94,13 +97,7 @@ module.exports = { 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 - } - }) + hyperfast(templates.post, renderPost(ctx)(post)) ); }, @@ -111,7 +108,7 @@ module.exports = { config, Case.title(value), hyperfast(templates.taxon, { - ".post": taxonItems.map(renderPostListItem(ctx)) + ".h-entry": taxonItems.map(renderPost(ctx)) }) ); } -- cgit 1.4.1