|
| 1 | +import * as Utilities from '~/common/utilities'; |
| 2 | +import { PageApiVersionContextType } from '~/providers/page-api-version'; |
| 3 | +import navigation from '~/public/static/constants/navigation.json'; |
| 4 | +import { NavigationRoute } from '~/types/common'; |
| 5 | + |
| 6 | +export const getRoutes = ( |
| 7 | + path: string, |
| 8 | + version: PageApiVersionContextType['version'] |
| 9 | +): NavigationRoute[] => { |
| 10 | + if (isReferencePath(path)) { |
| 11 | + return navigation.reference[version] as NavigationRoute[]; |
| 12 | + } else { |
| 13 | + return navigation[getPageSection(path)] as NavigationRoute[]; |
| 14 | + } |
| 15 | +}; |
| 16 | + |
| 17 | +export const isArchivePath = (path: string) => { |
| 18 | + return Utilities.pathStartsWith('archive', path); |
| 19 | +}; |
| 20 | + |
| 21 | +export const isReferencePath = (path: string) => { |
| 22 | + return Utilities.pathStartsWith('versions', path); |
| 23 | +}; |
| 24 | + |
| 25 | +export const isGeneralPath = (path: string) => { |
| 26 | + return navigation.generalDirectories.some(name => Utilities.pathStartsWith(name, path)); |
| 27 | +}; |
| 28 | + |
| 29 | +export const isFeaturePreviewPath = (path: string) => { |
| 30 | + return navigation.featurePreview.some(name => Utilities.pathStartsWith(name, path)); |
| 31 | +}; |
| 32 | + |
| 33 | +export const isPreviewPath = (path: string) => { |
| 34 | + return navigation.previewDirectories.some(name => Utilities.pathStartsWith(name, path)); |
| 35 | +}; |
| 36 | + |
| 37 | +export const isEasPath = (path: string) => { |
| 38 | + return navigation.easDirectories.some(name => Utilities.pathStartsWith(name, path)); |
| 39 | +}; |
| 40 | + |
| 41 | +export const getPageSection = (path: string) => { |
| 42 | + if (isReferencePath(path)) { |
| 43 | + return 'reference'; |
| 44 | + } else if (isEasPath(path)) { |
| 45 | + return 'eas'; |
| 46 | + } else if (isGeneralPath(path)) { |
| 47 | + return 'general'; |
| 48 | + } else if (isFeaturePreviewPath(path)) { |
| 49 | + return 'featurePreview'; |
| 50 | + } else if (isPreviewPath(path)) { |
| 51 | + return 'preview'; |
| 52 | + } else if (isArchivePath(path)) { |
| 53 | + return 'archive'; |
| 54 | + } |
| 55 | + |
| 56 | + return 'general'; |
| 57 | +}; |
0 commit comments