familyfedie-website/src/lib/static-pages.ts
Loyyd d74495ddef
Some checks are pending
/ deploy (push) Waiting to run
new source of truth
2026-06-11 10:01:45 +02:00

45 lines
1.3 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
export const repoRoot = process.cwd();
export const legacyHtmlRoot = path.join(repoRoot, "archive-source");
export const migratedHtmlPages = new Set([
"about.html",
"contact.html",
"events.html",
"index.html",
"services.html",
"the-founders.html",
"videos.html",
]);
export function walkHtmlFiles(dir = legacyHtmlRoot): string[] {
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
return walkHtmlFiles(fullPath);
}
return entry.isFile() && entry.name.endsWith(".html") ? [fullPath] : [];
});
}
export function relativeWebsitePath(filePath: string): string {
return path.relative(legacyHtmlRoot, filePath).split(path.sep).join("/");
}
export function routeFromRelativePath(relativePath: string): string {
if (relativePath === "index.html") {
return "";
}
return relativePath;
}
export function isMigratedHtmlPage(relativePath: string): boolean {
return migratedHtmlPages.has(relativePath);
}
export function sourcePathFromRoute(route = ""): string {
const relativePath = route === "" ? "index.html" : route.endsWith(".html") ? route : `${route}/index.html`;
return path.join(legacyHtmlRoot, relativePath);
}