export type PrimaryNavigationCurrent = "page" | "location"; export interface PrimaryNavigationItem { href: string; label: string; icon?: "horse-toy"; ariaCurrent?: PrimaryNavigationCurrent; } interface PrimaryNavigationDefinition { href: string; label: string; icon?: PrimaryNavigationItem["icon"]; pagePaths: string[]; sectionPath: string; } const PRIMARY_NAVIGATION: PrimaryNavigationDefinition[] = [ { href: "/", label: "Board", pagePaths: ["/", "/tasks"], sectionPath: "/tasks", }, { href: "/inbox", label: "Inbox", pagePaths: ["/inbox"], sectionPath: "/inbox", }, { href: "/docs", label: "Docs", pagePaths: ["/docs"], sectionPath: "/docs", }, { href: "/instructions", label: "Instructions", pagePaths: ["/instructions"], sectionPath: "/instructions", }, { href: "/pony", label: "Pony information", icon: "horse-toy", pagePaths: ["/pony"], sectionPath: "/pony", }, ]; /** * Exact paths represent the linked page, while slash-delimited descendants * represent its section. The delimiter prevents similarly prefixed routes * such as `/inbox-settings` from becoming current accidentally. */ export function getPrimaryNavigation( pathname: string, ): PrimaryNavigationItem[] { return PRIMARY_NAVIGATION.map((item) => { const isPage = item.pagePaths.includes(pathname); const isSection = pathname.startsWith(`${item.sectionPath}/`); return { href: item.href, label: item.label, ...(item.icon ? { icon: item.icon } : {}), ...(isPage || isSection ? { ariaCurrent: isPage ? ("page" as const) : ("location" as const) } : {}), }; }); }