feat: Use microformats classes Add snapshot-based tests to ensure microformats data can be extracted correctly.
1 file changed, 14 insertions(+), 17 deletions(-)
changed files
M src/responders.js → src/responders.js
@@ -21,7 +21,7 @@ return re.exec(getTemplate(template))[1].length; } const findMain = /^(\s+)<main/m; const baseIndentLevel = getTemplateIndent(findMain, "layout"); -const findPostContent = /^(\s+)<div class="post-content/m; +const findPostContent = /^(\s+)<div class="e-content/m; const postIndentLevel = baseIndentLevel + getTemplateIndent(findPostContent, "post");@@ -49,12 +49,15 @@ datetime: date.toISOString(), _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 @@ 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 @@ ctx.body = layout( config, null, hyperfast(templates.home, { - ".post": posts.map(renderPostListItem(ctx)) + ".h-entry": posts.map(renderPost(ctx)) }) ); },@@ -94,13 +97,7 @@ 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 @@ ctx.body = layout( config, Case.title(value), hyperfast(templates.taxon, { - ".post": taxonItems.map(renderPostListItem(ctx)) + ".h-entry": taxonItems.map(renderPost(ctx)) }) ); }