astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
27 lines (26 loc) • 676 B
JavaScript
function pathHasLocale(path, locales) {
const segments = path.split("/").map(normalizeThePath);
for (const segment of segments) {
for (const locale of locales) {
if (typeof locale === "string") {
if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
return true;
}
} else if (segment === locale.path) {
return true;
}
}
}
return false;
}
function normalizeTheLocale(locale) {
return locale.replaceAll("_", "-").toLowerCase();
}
function normalizeThePath(path) {
return path.endsWith(".html") ? path.slice(0, -5) : path;
}
export {
normalizeTheLocale,
normalizeThePath,
pathHasLocale
};