blog/src/index.tsx

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-07-03 02:35:01 +00:00
import { Hono } from 'hono';
import { jsxRenderer, useRequestContext } from 'hono/jsx-renderer';
import { Page } from '@blog/templates/Page';
import home from '@blog/routes/home';
2024-07-04 02:13:04 +00:00
import posts from '@blog/routes/posts';
import type { SiteMeta } from '@blog/model/SiteMeta';
2024-07-07 02:03:40 +00:00
import { setupDb, readPostsToDatabase } from '@blog/db/init';
2024-07-04 02:13:04 +00:00
declare module 'hono' {
interface ContextRenderer {
(content: string|Promise<string>, props: { meta: SiteMeta }): Response;
}
}
2024-07-03 02:35:01 +00:00
2024-07-07 02:03:40 +00:00
async function main() {
console.log({ message: "Starting the Blog application..." });
const app = new Hono();
2024-07-03 02:35:01 +00:00
2024-07-07 02:03:40 +00:00
// Render the JSX views
console.log({ message: "Bootstrapping the view layer..." });
app.get(
'*',
jsxRenderer(
({ children, meta }) => {
return (<Page meta={meta}>{children}</Page>);
},
{
docType: true
}
)
);
2024-07-03 02:35:01 +00:00
2024-07-07 02:03:40 +00:00
// Bootstrap the Database
console.log({ message: "Bootstrapping the database..." });
setupDb();
await readPostsToDatabase(__dirname + "/../posts");
2024-07-03 02:35:01 +00:00
2024-07-07 02:03:40 +00:00
// read all posts
// create listing of posts
console.log({ message: "Bootstrapping the routes..." });
app.route('/', home);
app.route('/posts', posts);
return app;
}
export default main();
2024-07-03 02:35:01 +00:00