All checks were successful
CI — Website / Website — typecheck, build (pull_request) Successful in 57s
35 lines
877 B
TypeScript
35 lines
877 B
TypeScript
import routesFile from './seo.routes.json';
|
|
|
|
export const SITE_ORIGIN = routesFile.origin;
|
|
|
|
export type SeoRoute = {
|
|
path: string;
|
|
title: string;
|
|
description: string;
|
|
index: boolean;
|
|
};
|
|
|
|
export const INDEXABLE_ROUTES: SeoRoute[] = routesFile.routes.map((r) => ({
|
|
...r,
|
|
index: true,
|
|
}));
|
|
|
|
export const NOT_FOUND_SEO: SeoRoute = {
|
|
path: '',
|
|
title: 'Page not found — LexAI',
|
|
description: 'That address is not a LexAI page.',
|
|
index: false,
|
|
};
|
|
|
|
const byPath = new Map(INDEXABLE_ROUTES.map((r) => [r.path, r]));
|
|
|
|
export function seoForPath(pathname: string): SeoRoute {
|
|
const normalized = pathname.replace(/\/+$/, '') || '/';
|
|
return byPath.get(normalized) ?? NOT_FOUND_SEO;
|
|
}
|
|
|
|
export function canonicalUrl(path: string): string {
|
|
if (!path || path === '/') return `${SITE_ORIGIN}/`;
|
|
return `${SITE_ORIGIN}${path.startsWith('/') ? path : `/${path}`}`;
|
|
}
|