From ad56116d0df26b4a6fe7f9cd04a21965d3184af5 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 3 Oct 2017 15:30:54 +0200 Subject: Reify taxonomies into just tags. I'm probably not going to need anything else, and this makes it a lot clearer --- src/domain/posts.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/domain') diff --git a/src/domain/posts.js b/src/domain/posts.js index c6b57c5..1214072 100644 --- a/src/domain/posts.js +++ b/src/domain/posts.js @@ -68,33 +68,29 @@ async function getFolder(folder, getURL) { return new Map(posts.map(f => [getTitle(f), f])); } -function taxonomise(taxonomies, posts) { - const taxons = new Map(Object.keys(taxonomies).map(t => [t, new Map()])); +function tag(posts) { + const tags = new Map(); for (let [, post] of posts) { - for (let [singularName, pluralName] of Object.entries(taxonomies)) { - if (post.data.has(pluralName)) { - for (let term of post.data.get(pluralName)) { - const current = taxons.get(singularName).get(term); - taxons - .get(singularName) - .set(term, current ? current.concat(post) : [post]); - } + if (post.data.has("tags")) { + for (let term of post.data.get("tags")) { + const current = tags.get(term); + tags.set(term, current ? current.concat(post) : [post]); } } } - return taxons; + return tags; } module.exports = async function(config, getURL) { const posts = await getFolder(config.folder, getURL); - const taxonomies = taxonomise(config.taxonomies, posts); + const tags = tag(posts); const lastPostDate = Math.max(Array.from(posts.values(), p => p.date)); return { lastPostDate, posts, - taxonomies, + tags, get }; }; -- cgit 1.4.1