familyfedie-website/src/pages/[...route].ts

26 lines
867 B
TypeScript

import fs from "node:fs/promises";
import { contentSourceRoutes } from "../lib/content-routes";
import { isMigratedHtmlPage, relativeWebsitePath, routeFromRelativePath, sourcePathFromRoute, walkHtmlFiles } from "../lib/static-pages";
export async function getStaticPaths() {
const markdownRoutes = await contentSourceRoutes();
return walkHtmlFiles()
.map(relativeWebsitePath)
.filter((relativePath) => !isMigratedHtmlPage(relativePath) && !markdownRoutes.has(relativePath))
.map((relativePath) => ({
params: {
route: routeFromRelativePath(relativePath),
},
}));
}
export async function GET({ params }: { params: { route?: string } }) {
const html = await fs.readFile(sourcePathFromRoute(params.route), "utf8");
return new Response(html, {
headers: {
"content-type": "text/html; charset=utf-8",
},
});
}