familyfedie-website/src/lib/static-pages.ts
2026-06-11 18:31:35 +00:00

67 lines
2 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([
"2013-sunday-service-archive.html",
"2014-sunday-services.html",
"2015-sunday-services-archive.html",
"2016-sunday-service-archive.html",
"2017-sunday-service-archive.html",
"2018-sunday-service-archive.html",
"about.html",
"about-us-organizations.html",
"archive-sunday-services-2013.html",
"archive-sunday-services-2014.html",
"archive-sunday-services-2015.html",
"archive-sunday-services-2016.html",
"archive-sunday-services-2017.html",
"archive-sunday-services-2018.html",
"contact.html",
"events.html",
"index.html",
"register.html",
"services.html",
"speeches/index.html",
"the-founders.html",
"videos.html",
]);
const migratedHtmlPrefixes = [
"blog/categories/",
"blog/tags/",
"speeches/categories/",
"speeches/rev-dr-sun-myung-moon/",
];
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) || migratedHtmlPrefixes.some((prefix) => relativePath.startsWith(prefix));
}
export function sourcePathFromRoute(route = ""): string {
const relativePath = route === "" ? "index.html" : route.endsWith(".html") ? route : `${route}/index.html`;
return path.join(legacyHtmlRoot, relativePath);
}