Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/lukebennett88/luke-ui. ui.lukebennett.dev
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930export interface SiteDestination { activePath?: string; label: string; url: string;}
export const siteDestinations: ReadonlyArray<SiteDestination> = [ { activePath: '/docs', label: 'Docs', url: '/docs/installation' }, { activePath: '/components', label: 'Components', url: '/components' }, { activePath: '/playground', label: 'Playground', url: '/playground' },];
export function getActiveSiteDestination(pathname: string): SiteDestination | undefined { let match: SiteDestination | undefined;
for (const destination of siteDestinations) { const { activePath } = destination; if (activePath === undefined) continue; if (!isAtOrBelow(pathname, activePath)) continue; if (match?.activePath !== undefined && match.activePath.length >= activePath.length) continue; match = destination; }
return match;}
function isAtOrBelow(pathname: string, activePath: string): boolean { return pathname === activePath || pathname.startsWith(`${activePath}/`);}