diff options
author | Alan Pearce | 2017-06-18 21:01:14 +0200 |
---|---|---|
committer | Alan Pearce | 2017-06-18 21:01:14 +0200 |
commit | e58d6a1718b3358f91fbda10e2291ea4ec01d1e7 (patch) | |
tree | c907d8c0b04f25decd2b64f29ebd80e7aa157724 /src/modules | |
parent | 2fef943bf1c52e8d2be64521202936ca0f7358e3 (diff) | |
download | homestead-e58d6a1718b3358f91fbda10e2291ea4ec01d1e7.tar.lz homestead-e58d6a1718b3358f91fbda10e2291ea4ec01d1e7.tar.zst homestead-e58d6a1718b3358f91fbda10e2291ea4ec01d1e7.zip |
feat: make taxonomies configurable
Add "tag" and "category" as defaults
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/posts.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/modules/posts.js b/src/modules/posts.js index cba2372..cf2d80e 100644 --- a/src/modules/posts.js +++ b/src/modules/posts.js @@ -56,21 +56,33 @@ function getFolder (folder) { ) } -function toTags (posts) { - const tags = new Map() +function taxonomise (taxonomies, posts) { + const taxons = new Map(Object.keys(taxonomies).map(t => [t, new Map()])) + for (let [, post] of posts) { - if (post.data.has('tags')) { - for (let tag of post.data.get('tags')) { - tags.set(tag, (tags.get(tag) || []).concat([post])) + 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]) + } } } } - return tags + + return taxons +} + +function toTags (posts) { + return taxonomise({ tag: 'tags' }, posts).get('tag') } module.exports = { get, getFolder, toTags, + taxonomise, render } |