summary refs log tree commit diff stats
path: root/src/index.js
diff options
context:
space:
mode:
authorAlan Pearce2017-06-18 13:36:29 +0200
committerAlan Pearce2017-06-18 13:36:29 +0200
commit69af7f12ec17f0aba65b0e23ef4045ee28f2dac8 (patch)
tree281781690d7bfe4952205e33ec26dff2f442aa57 /src/index.js
parent370e7add837f194bebc710c10ccd11bacfc74990 (diff)
downloadhomestead-69af7f12ec17f0aba65b0e23ef4045ee28f2dac8.tar.lz
homestead-69af7f12ec17f0aba65b0e23ef4045ee28f2dac8.tar.zst
homestead-69af7f12ec17f0aba65b0e23ef4045ee28f2dac8.zip
feat: add single post endpoint
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/index.js b/src/index.js
index 3d25faa..f691930 100644
--- a/src/index.js
+++ b/src/index.js
@@ -15,9 +15,17 @@ const posts = Posts.getFolder(process.env.POST_DIR)
 
 app.use(view(`${__dirname}/views`))
 
-router.get('/', async function (ctx, next) {
+const postsArray = Array.from(posts.entries())
+router.get('/', async function (ctx) {
   await ctx.render('index', {
-    posts
+    posts: postsArray
+  })
+})
+
+router.get('/post/:filename', async function (ctx) {
+  ctx.assert(posts.has(ctx.params.filename), 404, 'Post not found')
+  await ctx.render('post', {
+    post: posts.get(ctx.params.filename)
   })
 })