From 1a36d4dc311a86246fe854da888af01f8195368e Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 18 Jun 2017 17:23:06 +0200 Subject: refactor: move tag indexing of posts to Posts --- src/modules/posts.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/posts.js b/src/modules/posts.js index 834d45c..011292b 100644 --- a/src/modules/posts.js +++ b/src/modules/posts.js @@ -44,7 +44,20 @@ function getFolder (folder) { ) } +function toTags (posts) { + const tags = 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])) + } + } + } + return tags +} + module.exports = { get, - getFolder + getFolder, + toTags } -- cgit 1.4.1