1import * as Utilities from '~/common/utilities'; 2import { PageApiVersionContextType } from '~/providers/page-api-version'; 3import navigation from '~/public/static/constants/navigation.json'; 4import { NavigationRoute } from '~/types/common'; 5 6export 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 17export const isArchivePath = (path: string) => { 18 return Utilities.pathStartsWith('archive', path); 19}; 20 21export const isVersionedPath = (path: string) => { 22 return Utilities.pathStartsWith('versions', path); 23}; 24 25export const isReferencePath = (path: string) => { 26 return navigation.referenceDirectories.some(name => Utilities.pathStartsWith(name, path)); 27}; 28 29export const isHomePath = (path: string) => { 30 return navigation.homeDirectories.some(name => Utilities.pathStartsWith(name, path)); 31}; 32 33export const isGeneralPath = (path: string) => { 34 return navigation.generalDirectories.some(name => Utilities.pathStartsWith(name, path)); 35}; 36 37export const isFeaturePreviewPath = (path: string) => { 38 return navigation.featurePreview.some(name => Utilities.pathStartsWith(name, path)); 39}; 40 41export const isPreviewPath = (path: string) => { 42 return navigation.previewDirectories.some(name => Utilities.pathStartsWith(name, path)); 43}; 44 45export const isLearnPath = (path: string) => { 46 return navigation.learnDirectories.some(name => Utilities.pathStartsWith(name, path)); 47}; 48 49export const getPageSection = (path: string) => { 50 if (isReferencePath(path)) { 51 return 'reference'; 52 } else if (isGeneralPath(path)) { 53 return 'general'; 54 } else if (isFeaturePreviewPath(path)) { 55 return 'featurePreview'; 56 } else if (isPreviewPath(path)) { 57 return 'preview'; 58 } else if (isArchivePath(path)) { 59 return 'archive'; 60 } else if (isLearnPath(path)) { 61 return 'learn'; 62 } else if (isHomePath(path)) { 63 return 'home'; 64 } 65 66 return 'home'; 67}; 68