google search index
All checks were successful
CI — Website / Website — typecheck, build (pull_request) Successful in 57s
All checks were successful
CI — Website / Website — typecheck, build (pull_request) Successful in 57s
This commit is contained in:
34
packages/website/src/seo.ts
Normal file
34
packages/website/src/seo.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
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}`}`;
|
||||
}
|
||||
Reference in New Issue
Block a user