import { renderToString } from "react-dom/server";
import fs from "node:fs/promises";
import path from "path";
import { createRouter } from "@tanstack/react-router";
import { routeTree } from "../src/routeTree.gen";
async function build() {
const router = createRouter({ routeTree });
const mdxRoutes =
router.routesByPath["/docs/$slug"].options.staticData?.slugs?.map(
(slug) => `/docs/${slug}`,
) ?? [];
const routes = ["/", ...mdxRoutes];
for (const route of routes) {
const html = renderToString(/** what to do */);
const outputPath = path.join(
"dist",
route === "/" ? "index.html" : `${route}/index.html`,
);
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, html);
}
}
build().catch(console.error);
import { renderToString } from "react-dom/server";
import fs from "node:fs/promises";
import path from "path";
import { createRouter } from "@tanstack/react-router";
import { routeTree } from "../src/routeTree.gen";
async function build() {
const router = createRouter({ routeTree });
const mdxRoutes =
router.routesByPath["/docs/$slug"].options.staticData?.slugs?.map(
(slug) => `/docs/${slug}`,
) ?? [];
const routes = ["/", ...mdxRoutes];
for (const route of routes) {
const html = renderToString(/** what to do */);
const outputPath = path.join(
"dist",
route === "/" ? "index.html" : `${route}/index.html`,
);
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, html);
}
}
build().catch(console.error);