feat: add tags endpoint
1 file changed, 16 insertions(+), 0 deletions(-)
changed files
M src/index.js → src/index.js
@@ -29,6 +29,22 @@ post: posts.get(ctx.params.filename) }) }) +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