export interface SiteDestination { activePath?: string; label: string; url: string; } export const siteDestinations: ReadonlyArray = [ { 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}/`); }