Remove .html from internal links
Some checks are pending
/ deploy (push) Waiting to run

This commit is contained in:
Loyyd 2026-07-02 19:44:40 +02:00
parent 670d90cb15
commit f85aca7d58
43 changed files with 202 additions and 97 deletions

View file

@ -11,6 +11,36 @@ function copyDir(source, destination) {
fs.cpSync(source, destination, { recursive: true });
}
function listHtmlFiles(dir) {
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
return listHtmlFiles(fullPath);
}
return entry.isFile() && entry.name.endsWith(".html") ? [fullPath] : [];
});
}
function materializeExtensionlessHtmlRoutes() {
let routes = 0;
for (const filePath of listHtmlFiles(distRoot)) {
const relativePath = path.relative(distRoot, filePath);
const extensionlessPath = relativePath.replace(/\.html$/, "");
const destination = path.join(distRoot, extensionlessPath, "index.html");
if (path.resolve(destination) === path.resolve(filePath)) {
continue;
}
fs.mkdirSync(path.dirname(destination), { recursive: true });
fs.copyFileSync(filePath, destination);
routes += 1;
}
return routes;
}
for (const dir of staticDirs) {
copyDir(path.join(repoRoot, dir), path.join(distRoot, dir));
}
@ -30,4 +60,7 @@ if (fs.existsSync(adminIndexSource)) {
fs.copyFileSync(adminIndexSource, adminIndexDestination);
}
const extensionlessRoutes = materializeExtensionlessHtmlRoutes();
console.log(`Copied ${staticDirs.join(", ")} into dist/.`);
console.log(`Materialized ${extensionlessRoutes} extensionless HTML route aliases.`);