diff options
author | Alan Pearce | 2017-07-02 15:30:20 +0200 |
---|---|---|
committer | Alan Pearce | 2017-07-02 15:30:20 +0200 |
commit | b7bf162e6c3bc834097e65936704e3eac59eb4bd (patch) | |
tree | 9f080d9c67d6ee17a506e5ab52761f22b649137c /src/responders.js | |
parent | 2d931962b74fe06c1bfbc2454fa166d24e8e2f59 (diff) | |
download | homestead-b7bf162e6c3bc834097e65936704e3eac59eb4bd.tar.lz homestead-b7bf162e6c3bc834097e65936704e3eac59eb4bd.tar.zst homestead-b7bf162e6c3bc834097e65936704e3eac59eb4bd.zip |
feat: Use microformats classes
Add snapshot-based tests to ensure microformats data can be extracted correctly.
Diffstat (limited to 'src/responders.js')
-rw-r--r-- | src/responders.js | 31 |
1 files changed, 14 insertions, 17 deletions
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+)<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 @@ const makeTime = date => ({ _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)) }) ); } |