diff options
author | Alan Pearce | 2017-06-18 14:12:25 +0200 |
---|---|---|
committer | Alan Pearce | 2017-06-18 14:12:25 +0200 |
commit | 1f2a6245ab1e503dee017ab617aaeda816ecb383 (patch) | |
tree | b8aa5820fa5661b652f5f55a9a1e48f9824241eb /src/index.js | |
parent | 69af7f12ec17f0aba65b0e23ef4045ee28f2dac8 (diff) | |
download | homestead-1f2a6245ab1e503dee017ab617aaeda816ecb383.tar.lz homestead-1f2a6245ab1e503dee017ab617aaeda816ecb383.tar.zst homestead-1f2a6245ab1e503dee017ab617aaeda816ecb383.zip |
feat: add tags endpoint
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js index f691930..e811be0 100644 --- a/src/index.js +++ b/src/index.js @@ -29,6 +29,22 @@ 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])) + } + } +} +router.get('/tags/:tag', async function (ctx) { + ctx.assert(tags.has(ctx.params.tag), 404, 'Tag not found') + await ctx.render('tag', { + tag: ctx.params.tag, + posts: tags.get(ctx.params.tag) + }) +}) + app.use(router.routes()).use(router.allowedMethods()) module.exports = app |