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

@ -4,6 +4,7 @@ import path from "node:path";
const repoRoot = process.cwd();
const distRoot = path.join(repoRoot, "dist");
const htmlAttributes = ["href", "src", "poster", "action"];
const internalHosts = new Set(["familyfed.ie", "www.familyfed.ie", "familyfed.bcgen.ie"]);
const assetExtensions = new Set([
".avif",
".css",
@ -98,6 +99,15 @@ function listFiles(dir) {
}
function checkReference({ sourceFile, rawReference, sourceKind }) {
if ((sourceKind === "href" || sourceKind === "action") && isInternalHtmlPageReference(rawReference)) {
problems.push({
sourceFile,
sourceKind,
rawReference,
reason: "internal page links should omit the .html extension",
});
}
const reference = normalizeReference(rawReference);
if (!reference) {
@ -140,6 +150,33 @@ function checkReference({ sourceFile, rawReference, sourceKind }) {
return 1;
}
function isInternalHtmlPageReference(rawReference) {
const trimmed = rawReference.trim();
if (
trimmed === "" ||
trimmed.startsWith("#") ||
trimmed.startsWith("data:") ||
trimmed.startsWith("blob:") ||
trimmed.startsWith("//") ||
trimmed.startsWith("?")
) {
return false;
}
const absoluteMatch = trimmed.match(/^https?:\/\/([^/?#]+)([^?#]*)(?:[?#].*)?$/i);
if (absoluteMatch) {
const [, host, pathname] = absoluteMatch;
return internalHosts.has(host.toLowerCase()) && pathname.toLowerCase().endsWith(".html");
}
if (ignoredProtocols.test(trimmed)) {
return false;
}
const pathname = trimmed.split("#")[0].split("?")[0];
return pathname.toLowerCase().endsWith(".html");
}
function normalizeReference(rawReference) {
if (!rawReference) {
return "";