diff --git a/bun.lockb b/bun.lockb index 01bf513..6927e45 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/model/SiteMeta.ts b/src/model/SiteMeta.ts index 2765927..cb7d6c7 100644 --- a/src/model/SiteMeta.ts +++ b/src/model/SiteMeta.ts @@ -2,4 +2,5 @@ export type SiteMeta = { description?: string, tags?: string[], author?: string, + viewport?: string, }; diff --git a/src/util/post-reader.ts b/src/post/post-reader.ts similarity index 62% rename from src/util/post-reader.ts rename to src/post/post-reader.ts index e9ea633..bf2ab34 100644 --- a/src/util/post-reader.ts +++ b/src/post/post-reader.ts @@ -2,6 +2,7 @@ import { marked } from 'marked'; import type { Post } from '@blog/model/Post'; import type { PostMeta } from '@blog/model/PostMeta'; import * as yamlFront from 'yaml-front-matter'; +import { readdir } from 'node:fs/promises'; export async function openPostMarkdownFile(filename: string): Promise { const file = Bun.file(filename); @@ -22,15 +23,35 @@ export function parsePostMetadata(post: string): PostMetaWithRawContent { description: parsedData.description, date: new Date(parsedData.date), draft: parsedData?.draft || false, - tags: parsedData.tags + tags: parsedData.tags, }, content: parsedData.__content }; } +export async function getPostList(path: string): Promise { + const postList: PostMeta[] = new Array(); + console.log(path); + const dir = await readdir(path); + + if (!dir.length) { + return postList; + } + + for (const file of dir) { + const fileContent = await openPostMarkdownFile(path + '/' + file); + const postMeta = parsePostMetadata(fileContent); + postMeta.meta.slug = "/posts/" + file.slice(0, -3); + postList.push(postMeta.meta); + } + + return postList; +} + export async function readPostMarkdown(filename: string): Promise { const contents = await openPostMarkdownFile(filename); const post = parsePostMetadata(contents); + post.meta.slug = "/posts/" + filename.slice(0, -3); const parsedPost = await marked.parse(post.content); return { diff --git a/src/routes/home.tsx b/src/routes/home.tsx index d0adf2c..6489ae3 100644 --- a/src/routes/home.tsx +++ b/src/routes/home.tsx @@ -1,13 +1,17 @@ import { Hono } from 'hono'; -import { readdir } from 'node:fs/promises'; import { Home } from '@blog/templates/Pages/Home'; +import { getPostList } from '@blog/post/post-reader'; +import { PostMeta } from '@blog/model/PostMeta'; 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(); + const postDir = __dirname + '/../../posts'; + const postList: PostMeta[] = await getPostList(postDir); + + return c.render(, { meta: { + description: "The blog for Dave Smith-Hayes, a dad and developer." + }}); }); export default app; diff --git a/src/routes/posts.tsx b/src/routes/posts.tsx index c484259..278745a 100644 --- a/src/routes/posts.tsx +++ b/src/routes/posts.tsx @@ -3,7 +3,7 @@ import { PostPage } from '@blog/templates/Pages/PostPage'; import { FourOhFour } from '@blog/templates/Pages/FourOhFour'; import { readdir } from 'node:fs/promises'; import { SiteMeta } from '@blog/model/SiteMeta'; -import { readPostMarkdown } from '@blog/util/post-reader'; +import { readPostMarkdown } from '@blog/post/post-reader'; const app = new Hono(); diff --git a/src/templates/Pages/Home.tsx b/src/templates/Pages/Home.tsx index f764666..166427d 100644 --- a/src/templates/Pages/Home.tsx +++ b/src/templates/Pages/Home.tsx @@ -1,6 +1,7 @@ import { PostList } from '@blog/templates/components/PostList'; +import { PostMeta } from '@blog/model/PostMeta'; -export function Home({ posts }: { posts: string[] }) { +export function Home({ posts }: { posts: PostMeta[] }) { return (

davesmithhayes.com

diff --git a/src/templates/components/MetaTags.tsx b/src/templates/components/MetaTags.tsx index 9316307..27f3233 100644 --- a/src/templates/components/MetaTags.tsx +++ b/src/templates/components/MetaTags.tsx @@ -24,12 +24,25 @@ export function Author({ meta }: { meta: SiteMeta }) { return (); } +export function ViewPort({ meta }: { meta: SiteMeta }) { + if (!meta?.viewport) { + return ( + + ); + } + + return (); +} + export function MetaTags({ meta }: { meta: SiteMeta }) { return ( <> + ) } diff --git a/src/templates/components/PostList.tsx b/src/templates/components/PostList.tsx index 75712da..bc222a8 100644 --- a/src/templates/components/PostList.tsx +++ b/src/templates/components/PostList.tsx @@ -1,9 +1,9 @@ -import type { Post } from '@blog/model/Post'; +import type { PostMeta } from '@blog/model/PostMeta'; -export function PostList(postList: Post[]) { +export function PostList({ posts }: { posts: PostMeta[] }) { return(
    - {postList.map(p => { + {posts.map(p => { return (
  • {p.title}