From db3e79fd8f3bce57619a870f75633aad2567374d Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Mon, 8 Jul 2024 21:37:25 -0400 Subject: [PATCH] Re-organize the repository. --- src/config.ts | 2 ++ src/{routes => handlers}/home.tsx | 0 src/{routes => handlers}/posts.tsx | 0 src/index.tsx | 54 +++++++++++------------------- src/{model => models}/Post.ts | 0 src/{model => models}/PostMeta.ts | 0 src/{model => models}/SiteMeta.ts | 0 src/services/database.ts | 7 ++++ src/services/post-file.ts | 5 +++ 9 files changed, 33 insertions(+), 35 deletions(-) create mode 100644 src/config.ts rename src/{routes => handlers}/home.tsx (100%) rename src/{routes => handlers}/posts.tsx (100%) rename src/{model => models}/Post.ts (100%) rename src/{model => models}/PostMeta.ts (100%) rename src/{model => models}/SiteMeta.ts (100%) create mode 100644 src/services/database.ts create mode 100644 src/services/post-file.ts diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..6063c27 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,2 @@ +export const POST_PATH: string = __dirname + '/../posts'; +export const STATIC_PATH: string = __dirname + '/../static'; diff --git a/src/routes/home.tsx b/src/handlers/home.tsx similarity index 100% rename from src/routes/home.tsx rename to src/handlers/home.tsx diff --git a/src/routes/posts.tsx b/src/handlers/posts.tsx similarity index 100% rename from src/routes/posts.tsx rename to src/handlers/posts.tsx diff --git a/src/index.tsx b/src/index.tsx index 2bae649..9479e8e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,10 +1,9 @@ import { Hono } from 'hono'; -import { jsxRenderer, useRequestContext } from 'hono/jsx-renderer'; +import { jsxRenderer } from 'hono/jsx-renderer'; import { Page } from '@blog/templates/Page'; -import home from '@blog/routes/home'; -import posts from '@blog/routes/posts'; -import type { SiteMeta } from '@blog/model/SiteMeta'; -import { setupDb, readPostsToDatabase } from '@blog/db/init'; +import home from '@blog/handlers/home'; +import posts from '@blog/handlers/posts'; +import type { SiteMeta } from '@blog/models/SiteMeta'; declare module 'hono' { interface ContextRenderer { @@ -12,38 +11,23 @@ declare module 'hono' { } } -async function main() { - console.log({ message: "Starting the Blog application..." }); - const app = new Hono(); +const app = new Hono(); - // Render the JSX views - console.log({ message: "Bootstrapping the view layer..." }); - app.get( - '*', - jsxRenderer( - ({ children, meta }) => { - return ({children}); - }, - { - docType: true - } - ) - ); +// Render the JSX views +app.get( + '*', + jsxRenderer( + ({ children, meta }) => {children}, + { docType: true } + ) +); - // Bootstrap the Database - console.log({ message: "Bootstrapping the database..." }); - setupDb(); - await readPostsToDatabase(__dirname + "/../posts"); +console.log({ message: "Bootstrapping the routes..." }); +app.route('/', home); +app.route('/posts', posts); - // read all posts - // create listing of posts - - console.log({ message: "Bootstrapping the routes..." }); - app.route('/', home); - app.route('/posts', posts); - - return app; +export default { + port: process.env.APP_PORT || 3000, + fetch: app.fetch } -export default main(); - diff --git a/src/model/Post.ts b/src/models/Post.ts similarity index 100% rename from src/model/Post.ts rename to src/models/Post.ts diff --git a/src/model/PostMeta.ts b/src/models/PostMeta.ts similarity index 100% rename from src/model/PostMeta.ts rename to src/models/PostMeta.ts diff --git a/src/model/SiteMeta.ts b/src/models/SiteMeta.ts similarity index 100% rename from src/model/SiteMeta.ts rename to src/models/SiteMeta.ts diff --git a/src/services/database.ts b/src/services/database.ts new file mode 100644 index 0000000..3d4782e --- /dev/null +++ b/src/services/database.ts @@ -0,0 +1,7 @@ +export type ConnectionConfig = { + host: string, + username: string, + password: string, + database: string, + port: number +}; diff --git a/src/services/post-file.ts b/src/services/post-file.ts new file mode 100644 index 0000000..174eabc --- /dev/null +++ b/src/services/post-file.ts @@ -0,0 +1,5 @@ +import { POST_PATH } from '@blog/config'; + +export class PostFileService { + +}