WIP: Architecture Refactor, add stub files and working blog post wrapped by AppShell
This commit is contained in:
75
index.tsx
75
index.tsx
@@ -1,49 +1,38 @@
|
||||
// import { Elysia } from "elysia";
|
||||
// import { html } from "@elysiajs/html";
|
||||
// import { staticPlugin } from "@elysiajs/static";
|
||||
import AppShellDemo from "./temp/appshell.html";
|
||||
import { AppShell } from "./src/frontend/AppShell";
|
||||
|
||||
// import { AppShell } from "./src/frontend/AppShell";
|
||||
// import { app } from "./src/backend";
|
||||
async function blogPosts() {
|
||||
const glob = new Bun.Glob("**/*.md");
|
||||
const blogPosts: Record<string, any> = {}
|
||||
for await (const file of glob.scan("./content")) {
|
||||
const post = await import(`./content/${file}`, { with: { type: "html" } });
|
||||
const route = `/${file.replace(/\.md$/, "")}`;
|
||||
|
||||
// const index = new Elysia()
|
||||
// .use(html())
|
||||
// .onRequest(({ request }) => {
|
||||
// console.log(`Request ${request.method} ${request.url}`);
|
||||
// })
|
||||
// .onAfterHandle(({ request, responseValue }) => {
|
||||
// if (request.headers.get("shell-loaded") === "true") {
|
||||
// return responseValue; // Return the <main> element if the AppShell has already been loaded
|
||||
// }
|
||||
// return AppShell(responseValue); // Return the <main> element wrapped by the AppShell
|
||||
// })
|
||||
// .use(staticPlugin({
|
||||
// assets: './src/public',
|
||||
// prefix: '/public'
|
||||
// }))
|
||||
// .use(app)
|
||||
// .listen(3000);
|
||||
|
||||
// console.log(
|
||||
// `🦊 Elysia is running at ${index.server?.hostname}:${index.server?.port}`
|
||||
// );
|
||||
blogPosts[route] = post.default;
|
||||
}
|
||||
|
||||
|
||||
import { serve } from "bun";
|
||||
import AppShell from "./temp/appshell.html"
|
||||
|
||||
// Dynamically import all markdown files
|
||||
const glob = new Bun.Glob("**/*.md");
|
||||
const routes: Record<string, any> = {
|
||||
'/': AppShell,
|
||||
};
|
||||
|
||||
for await (const file of glob.scan("./content")) {
|
||||
const post = await import(`./content/${file}`, { with: { type: "html" } });
|
||||
const route = `/${file.replace(/\.md$/, '')}`;
|
||||
routes[route] = post.default;
|
||||
Object.keys(blogPosts).map((route) => {
|
||||
console.info(route);
|
||||
});
|
||||
return blogPosts;
|
||||
}
|
||||
|
||||
serve({
|
||||
routes,
|
||||
development: true,
|
||||
Bun.serve({
|
||||
development: {
|
||||
hmr: true,
|
||||
console: true
|
||||
},
|
||||
|
||||
routes: {
|
||||
"/": AppShellDemo,
|
||||
... await blogPosts(),
|
||||
"/content/*": {
|
||||
async GET(req: Request) {
|
||||
// Having trouble using Bun Bundler alongside a custom route handler to send
|
||||
// different content depending on the request headers, will use /content subpath instead
|
||||
// (unless I can figure it out)
|
||||
return new Response("This will send the blog post content without the app shell")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user