Files
Rental-operations-platform/contracts/phase9/implementation/hreflang-generator_v1.0.ts
T
2026-06-25 19:06:59 -04:00

14 lines
751 B
TypeScript

import manifest from "../localization/ROUTE_MANIFEST_v1.0.json";
type Locale = "en"|"fr"|"ar";
export function localizedPath(routeId:string, locale:Locale):string {
const route = manifest.routes.find((item) => item.id === routeId);
if (!route) throw new Error(`Unknown route: ${routeId}`);
const slug = route.slugs[locale];
return slug ? `/${locale}/${slug}` : `/${locale}`;
}
export function hreflangLinks(origin:string, routeId:string) {
const alternates = manifest.locales.map((locale) => ({ rel:"alternate", hreflang:locale, href:new URL(localizedPath(routeId, locale as Locale),origin).href }));
alternates.push({ rel:"alternate", hreflang:"x-default", href:new URL(localizedPath(routeId,"en"),origin).href });
return alternates;
}