From 0eae8ebbff134525ae7ae20b636915ac2e03264f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ade=E3=80=8C=E3=81=82=E3=81=A7=E3=80=8DFisher?= Date: Mon, 6 Jan 2025 00:49:56 +0100 Subject: [PATCH] spa static routes --- scripts/build.spa.tsx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/build.spa.tsx b/scripts/build.spa.tsx index 0d20c35..d7db01b 100644 --- a/scripts/build.spa.tsx +++ b/scripts/build.spa.tsx @@ -3,6 +3,7 @@ import project from "../package.json"; import { getHtml } from "../src/entry/_handlers"; import { assignToWindow } from "../src/utils/hydration"; import { Palette } from "../src/style/palette"; +import { ROUTES } from "../src/pages/_router"; // why does this work but running it from Bun.build fails? #justbunthings await $`bun build ./src/entry/client.tsx --outdir ./spa --minify`; @@ -15,15 +16,22 @@ await $`bun build ./src/entry/client.tsx --outdir ./spa --minify`; // } const baseUrl = process.env.BASE_URL; -const fullUrl = `${baseUrl ?? ""}/`; +const regex = /\/\w*/gm; -const html = getHtml( - fullUrl, - [assignToWindow("REALM", `"SPA"`), baseUrl && assignToWindow("BASE_URL", `"${baseUrl}"`)], - baseUrl, -); +for (const route of ROUTES) { + const path = route.path.match(regex)?.[0]!; + + const fullUrl = `${baseUrl ?? ""}${path}`; + + const html = getHtml( + fullUrl, + [assignToWindow("REALM", `"SPA"`), baseUrl && assignToWindow("BASE_URL", `"${baseUrl}"`)], + baseUrl, + ); + const pathname = path === "/" ? "index" : path.slice(1); -await Bun.write("./spa/index.html", html); + await Bun.write(`./spa/${pathname}.html`, html); +} const resolutions = [128, 192, 256, 512, 1024]; @@ -31,7 +39,7 @@ await Bun.write( "./spa/manifest.json", JSON.stringify({ name: project.name, - start_url: fullUrl, + start_url: `${baseUrl ?? ""}/`, display: "standalone", description: project.description, background_color: Palette.white, @@ -47,4 +55,4 @@ await Bun.write( for (const res of resolutions) { await $`cp ./.github/assets/experiment-${res}.png ./spa`; -} \ No newline at end of file +}