about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/index.js9
-rw-r--r--src/modules/posts.js15
2 files changed, 15 insertions, 9 deletions
diff --git a/src/index.js b/src/index.js
index e811be0..07d7249 100644
--- a/src/index.js
+++ b/src/index.js
@@ -29,14 +29,7 @@ router.get('/post/:filename', async function (ctx) {
   })
 })
 
-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]))
-    }
-  }
-}
+const tags = Posts.toTags(posts)
 router.get('/tags/:tag', async function (ctx) {
   ctx.assert(tags.has(ctx.params.tag), 404, 'Tag not found')
   await ctx.render('tag', {
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
 }