commit 2e7b5da0f9cca792f1df6ac25cc0101336585c27 Author: Dave Smith-Hayes Date: Tue Jul 2 22:35:01 2024 -0400 Start the blog diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8f08686 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.{js,ts,jsx,tsx,json}] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..506e4c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# deps +node_modules/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..6dd13e7 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +To install dependencies: +```sh +bun install +``` + +To run: +```sh +bun run dev +``` + +open http://localhost:3000 diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..01bf513 Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..f5a1b81 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "blog", + "scripts": { + "dev": "bun run --hot src/index.tsx" + }, + "dependencies": { + "@types/yaml-front-matter": "^4.1.3", + "hono": "^4.4.10", + "marked": "^13.0.1", + "remark": "^15.0.1", + "yaml-front-matter": "^4.1.1" + }, + "devDependencies": { + "@types/bun": "latest" + } +} diff --git a/src/Model/Post.ts b/src/Model/Post.ts new file mode 100644 index 0000000..d7d87dc --- /dev/null +++ b/src/Model/Post.ts @@ -0,0 +1,10 @@ +import { Tag } from '@blog/Model/Tag'; + +export type Post = { + title: string, + slug: string, + description: string, + content: string, + date: Date, + tags: string[] +}; diff --git a/src/index.tsx b/src/index.tsx new file mode 100644 index 0000000..f1de0e3 --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,38 @@ +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 { readdir } from 'node:fs/promises'; + +const app = new Hono(); + +app.get( + '*', + jsxRenderer( + ({ children }) => { + return ({children}); + }, + { + docType: true + } + ) +); + +// read all posts +// 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(); +}); + +app.get('/posts/:slug', (c) => { + const postSlug: string = c.req.param("slug"); + + // render post + // send to Post layout +}); + +export default app; diff --git a/src/readPostMarkdown.ts b/src/readPostMarkdown.ts new file mode 100644 index 0000000..5d02d1c --- /dev/null +++ b/src/readPostMarkdown.ts @@ -0,0 +1,21 @@ +import { marked } from 'marked'; +import type { Post } from '@blog/Model/Post'; +import * as yamlFront from 'yaml-front-matter'; + +export async function readPostMarkdown(filename: string): Promise { + const file = Bun.file(filename); + const contents = await file.text(); + + const parsedData = yamlFront.loadFront(contents); + const parsedPost = await marked.parse(parsedData.__content); + + return { + title: parsedData.title, + slug: filename.slice(0, -3), + description: parsedData.description, + date: new Date(parsedData.date), + tags: parsedData.tags, + content: parsedPost + }; +} + diff --git a/src/templates/Page.tsx b/src/templates/Page.tsx new file mode 100644 index 0000000..81f007a --- /dev/null +++ b/src/templates/Page.tsx @@ -0,0 +1,20 @@ +export function Page({ children }: { children: any }) { + return ( + + + davesmithhayes.com + + +
+ +
+
+ {children} +
+
+ +
+ + + ); +} diff --git a/src/templates/Pages/Home.tsx b/src/templates/Pages/Home.tsx new file mode 100644 index 0000000..f764666 --- /dev/null +++ b/src/templates/Pages/Home.tsx @@ -0,0 +1,11 @@ +import { PostList } from '@blog/templates/components/PostList'; + +export function Home({ posts }: { posts: string[] }) { + return ( +
+

davesmithhayes.com

+ {posts.length ? :
No posts.
} +
+ ); +} + diff --git a/src/templates/components/PostList.tsx b/src/templates/components/PostList.tsx new file mode 100644 index 0000000..e947abf --- /dev/null +++ b/src/templates/components/PostList.tsx @@ -0,0 +1,15 @@ +import type { Post } from '@blog/Model/Post'; + +export function PostList(postList: Post[]) { + return( +
    + {postList.map(p => { + return ( +
  • + {p.name} +
  • + ); + })} +
+ ); +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a7eb9c2 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "strict": true, + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx", + "paths": { + "@blog/*": [ "./src/*" ] + } + } +}