Cleanup AI slop and simplify db interface
This commit is contained in:
13
index.tsx
13
index.tsx
@@ -6,7 +6,7 @@ import { Home } from "./src/frontend/pages/home";
|
||||
import { NotFound } from "./src/frontend/pages/not-found";
|
||||
import demo from "./temp/appshell.html";
|
||||
import { Post } from "./src/frontend/pages/post";
|
||||
import { getPostWithTags, getAdjacentPosts } from "./src/db/index";
|
||||
import { dbConnection } from "./src/db";
|
||||
|
||||
async function blogPosts(hmr: boolean) {
|
||||
const glob = new Bun.Glob("**/*.md");
|
||||
@@ -14,15 +14,16 @@ async function blogPosts(hmr: boolean) {
|
||||
for await (const file of glob.scan("./content")) {
|
||||
const post = await import(`./content/${file}`, { with: { type: "html" } });
|
||||
const route = `/${file.replace(/\.md$/, "")}`;
|
||||
dbConnection.getAllTags();
|
||||
|
||||
if (hmr) {
|
||||
// Use Bun Importer plugin for hot reloading in the browser
|
||||
blogPosts[`/hmr${route}`] = post.default;
|
||||
} else {
|
||||
// Use the Database for sending just the HTML or the HTML and AppShell
|
||||
blogPosts[route] = (req: Request) => {
|
||||
blogPosts[route] = async (req: Request) => {
|
||||
const path = new URL(req.url).pathname;
|
||||
const post = getPostWithTags(path);
|
||||
const post = dbConnection.getPost(path);
|
||||
if (!post)
|
||||
return new Response(renderToString(<NotFound />), {
|
||||
status: 404,
|
||||
@@ -30,7 +31,7 @@ async function blogPosts(hmr: boolean) {
|
||||
});
|
||||
|
||||
// Get adjacent posts for navigation
|
||||
const { previousPost, nextPost } = getAdjacentPosts(post.path);
|
||||
const { previousPost, nextPost } = dbConnection.getAdjacentPosts(post.path);
|
||||
|
||||
const data = {
|
||||
title: post.title,
|
||||
@@ -91,7 +92,7 @@ Bun.serve({
|
||||
...(await blogPosts(false)),
|
||||
|
||||
// hot module replacement in development mode
|
||||
...(process.env.NODE_ENV === "development" ? (await blogPosts(true)) : []),
|
||||
...(process.env.NODE_ENV === "development" ? (await blogPosts(true)) : {}),
|
||||
|
||||
// Home page
|
||||
"/": (req: Request) => {
|
||||
@@ -108,7 +109,7 @@ Bun.serve({
|
||||
|
||||
return new Response(
|
||||
renderToString(
|
||||
<AppShell>
|
||||
<AppShell searchParams={searchParams}>
|
||||
<Home searchParams={searchParams} />
|
||||
</AppShell>,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user