| 1 | export interface NavItem { |
| 2 | title: string; |
| 3 | href: string; |
| 4 | } |
| 5 | |
| 6 | export interface NavSection { |
| 7 | title: string; |
| 8 | badge?: string; |
| 9 | defaultOpen?: boolean; |
| 10 | items: NavItem[]; |
| 11 | } |
| 12 | |
| 13 | export interface FlatNavItem extends NavItem { |
| 14 | section: string; |
| 15 | } |
| 16 | |
| 17 | export function flattenNavigation(): FlatNavItem[] { |
| 18 | return navigation.flatMap((s) => s.items.map((item) => ({ ...item, section: s.title }))); |
| 19 | } |
| 20 | |
| 21 | export function getPrevNext( |
| 22 | pathname: string, |
| 23 | basePath: string |
| 24 | ): { prev: FlatNavItem | null; next: FlatNavItem | null } { |
| 25 | const items = flattenNavigation(); |
| 26 | const index = items.findIndex( |
| 27 | (item) => |
| 28 | pathname === `${basePath}${item.href}/` || pathname === `${basePath}${item.href}` |
| 29 | ); |
| 30 | if (index === -1) return { prev: null, next: null }; |
| 31 | return { |
| 32 | prev: index > 0 ? items[index - 1] : null, |
| 33 | next: index < items.length - 1 ? items[index + 1] : null |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | export const guidesNavigation: NavSection[] = [ |
| 38 | { |
| 39 | title: 'Quick Start', |
| 40 | defaultOpen: true, |
| 41 | items: [ |
| 42 | { title: 'What is Portal?', href: '/what-is-portal' }, |
| 43 | { title: 'Prerequisites', href: '/prerequisites' }, |
| 44 | { title: 'Getting Started', href: '/getting-started' } |
| 45 | ] |
| 46 | }, |
| 47 | { |
| 48 | title: 'Core Concepts', |
| 49 | items: [ |
| 50 | { title: 'Overview', href: '/concepts' }, |
| 51 | { title: 'Architecture', href: '/architecture' }, |
| 52 | { title: 'Security Model', href: '/security-model' } |
| 53 | ] |
| 54 | }, |
| 55 | { |
| 56 | title: 'Guides', |
| 57 | items: [ |
| 58 | { title: 'Self-Hosting', href: '/self-hosting' }, |
| 59 | { title: 'Portal Agent', href: '/portal-agent' }, |
| 60 | { title: 'TCP/UDP Tunneling', href: '/tcp-udp-tunneling' }, |
| 61 | { title: 'Wallet and ENS', href: '/wallet-and-ens' }, |
| 62 | { title: 'Deployment', href: '/deployment' }, |
| 63 | { title: 'Configuration', href: '/configuration' } |
| 64 | ] |
| 65 | } |
| 66 | ]; |
| 67 | |
| 68 | export const referencesNavigation: NavSection[] = [ |
| 69 | { |
| 70 | title: 'Reference', |
| 71 | defaultOpen: true, |
| 72 | items: [ |
| 73 | { title: 'CLI Reference', href: '/cli-reference' }, |
| 74 | { title: 'API Reference', href: '/api-reference' } |
| 75 | ] |
| 76 | } |
| 77 | ]; |
| 78 | |
| 79 | export const navigation: NavSection[] = [...guidesNavigation, ...referencesNavigation]; |
| 80 | |
| 81 | const referenceHrefs = new Set( |
| 82 | referencesNavigation.flatMap((s) => s.items.map((i) => i.href)) |
| 83 | ); |
| 84 | |
| 85 | export function isReferencePage(pathname: string, basePath: string): boolean { |
| 86 | return referenceHrefs.has(pathname.replace(basePath, '').replace(/\/$/, '')); |
| 87 | } |