diff --git a/src/index.tsx b/src/index.tsx index f1de0e3..4164123 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,6 +2,7 @@ import { Hono } from 'hono'; import { jsxRenderer, useRequestContext } from 'hono/jsx-renderer'; import { Page } from '@blog/templates/Page'; import { Home } from '@blog/templates/Pages/Home'; +import { FourOhFour } from '@blog/templates/Pages/FourOhFour'; import { readdir } from 'node:fs/promises'; const app = new Hono(); @@ -28,8 +29,16 @@ app.get('/', async (c) => { return c.render(); }); -app.get('/posts/:slug', (c) => { +app.get('/posts/:slug', async (c) => { const postSlug: string = c.req.param("slug"); + const fileName: string = postSlug + '.md'; + const files = await readdir(__dirname + "/../posts"); + + const postFile = files.find(f => f === fileName); + if (!postFile) { + c.status(404); + return c.render(); + } // render post // send to Post layout diff --git a/src/templates/Pages/FourOhFour.tsx b/src/templates/Pages/FourOhFour.tsx new file mode 100644 index 0000000..b4f2027 --- /dev/null +++ b/src/templates/Pages/FourOhFour.tsx @@ -0,0 +1,10 @@ +import { Page } from '@blog/templates/Page'; + +export function FourOhFour() { + return ( + <> +

404 Error

+
Unable to find what you're looking for.
+ + ); +} diff --git a/src/readPostMarkdown.ts b/src/util/readPostMarkdown.ts similarity index 100% rename from src/readPostMarkdown.ts rename to src/util/readPostMarkdown.ts