diff --git a/src/index.tsx b/src/index.tsx index 93364bc..1aa8e08 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,11 +1,8 @@ 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 { Post } from '@blog/templates/Pages/Post'; -import { readdir } from 'node:fs/promises'; -import { readPostMarkdown } from '@blog/util/readPostMarkdown'; +import { renderHomePage } from '@blog/routes/home'; +import { renderPostPage } from '@blog/routes/post'; const app = new Hono(); @@ -25,24 +22,11 @@ app.get( // create listing of posts app.get('/', async (c) => { - const files = await readdir('../posts', { recursive: true }); - const posts = files.filter(f => f === '.' || f === '..'); - return c.render(); + return renderHomePage(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(); - } - - const post = await readPostMarkdown(__dirname + "/../posts/" + postFile); - return c.render(); + return renderPostPage(c); }); export default app; diff --git a/src/Model/Post.ts b/src/model/Post.ts similarity index 52% rename from src/Model/Post.ts rename to src/model/Post.ts index d7d87dc..e6d3435 100644 --- a/src/Model/Post.ts +++ b/src/model/Post.ts @@ -1,10 +1,9 @@ -import { Tag } from '@blog/Model/Tag'; - export type Post = { title: string, slug: string, - description: string, + description?: string, content: string, + html?: string, date: Date, - tags: string[] + tags?: string[] }; diff --git a/src/model/SiteMeta.ts b/src/model/SiteMeta.ts new file mode 100644 index 0000000..0c25bd6 --- /dev/null +++ b/src/model/SiteMeta.ts @@ -0,0 +1,4 @@ +export type SiteMeta = { + description: string, + tags: string[] +}; diff --git a/src/routes/home.tsx b/src/routes/home.tsx new file mode 100644 index 0000000..0334bf3 --- /dev/null +++ b/src/routes/home.tsx @@ -0,0 +1,13 @@ +import { Hono } from 'hono'; +import { readdir } from 'node:fs/promises'; +import { Home } from '@blog/templates/Pages/Home'; + +const app = new Hono(); + +app.get('/', async (c) => { + const files: string[] = await readdir(__dirname + '/../posts', { recursive: true }); + const posts: string[] = files.map(f => f.slice(0, -3)); + return c.render(); +}); + +export default app; diff --git a/src/routes/post.tsx b/src/routes/post.tsx new file mode 100644 index 0000000..c69c8b0 --- /dev/null +++ b/src/routes/post.tsx @@ -0,0 +1,26 @@ +import { Hono } from 'hono'; + +import { PostPage } from '@blog/templates/Pages/PostPage'; +import { FourOhFour } from '@blog/templates/Pages/FourOhFour'; +import { readdir } from 'node:fs/promises'; +import { readPostMarkdown } from '@blog/util/readPostMarkdown'; + +const app = new Hono(); + +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(); + } + + const post = await readPostMarkdown(__dirname + "/../posts/" + postFile); + return c.render(); +}); + +export default app; + diff --git a/src/templates/Page.tsx b/src/templates/Page.tsx index 81f007a..9031e86 100644 --- a/src/templates/Page.tsx +++ b/src/templates/Page.tsx @@ -1,12 +1,20 @@ -export function Page({ children }: { children: any }) { +import { css, Style } from 'hono/css'; +improt { SiteMeta } from '@blog/model/SiteMeta'; + +const logoClass = css` + font-size: 16pt; +`; + +export function Page({ children, meta }: { children: any, meta: Record }) { return ( davesmithhayes.com +