feat: make taxonomies configurable Add "tag" and "category" as defaults
1 file changed, 14 insertions(+), 7 deletions(-)
changed files
M src/index.js → src/index.js
@@ -37,14 +37,21 @@ post: 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', { - tag: ctx.params.tag, - posts: tags.get(ctx.params.tag) +const taxonomies = Posts.taxonomise(config.taxonomies, posts) +for (let [term, items] of taxonomies) { + router.get(`/${term}/:value`, async function (ctx) { + const value = ctx.params.value + ctx.assert( + items.has(ctx.params.value), + 404, + `Could not find ${term} ${value}` + ) + await ctx.render('tag', { + [term]: value, + posts: items.get(ctx.params.value) + }) }) -}) +} app.use(router.routes()).use(router.allowedMethods())