@@ -10,7 +10,7 @@ import useScrollToElement from '#site/hooks/useScrollToElement';
1010import useSiteNavigation from '#site/hooks/useSiteNavigation' ;
1111import { useRouter , usePathname } from '#site/navigation.mjs' ;
1212
13- import type { NavigationKeys } from '#site/types' ;
13+ import type { FormattedMessage , NavigationKeys } from '#site/types' ;
1414import type { RichTranslationValues } from 'next-intl' ;
1515import type { FC } from 'react' ;
1616
@@ -19,6 +19,27 @@ type WithSidebarProps = {
1919 context ?: Record < string , RichTranslationValues > ;
2020} ;
2121
22+ type MappedItem = {
23+ label : FormattedMessage ;
24+ link : string ;
25+ target ?: string ;
26+ items ?: Array < [ string , MappedItem ] > ;
27+ } ;
28+
29+ type SidebarMappedEntry = {
30+ label : FormattedMessage ;
31+ link : string ;
32+ target ?: string ;
33+ items ?: Array < SidebarMappedEntry > ;
34+ } ;
35+
36+ const mapItem = ( [ , item ] : [ string , MappedItem ] ) : SidebarMappedEntry => ( {
37+ label : item . label ,
38+ link : item . link ,
39+ target : item . target ,
40+ items : item . items ? item . items . map ( mapItem ) : [ ] ,
41+ } ) ;
42+
2243const WithSidebar : FC < WithSidebarProps > = ( { navKeys, context, ...props } ) => {
2344 const { getSideNavigation } = useSiteNavigation ( ) ;
2445 const pathname = usePathname ( ) ! ;
@@ -35,9 +56,9 @@ const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
3556 // If there's only a single navigation key, use its sub-items
3657 // as our navigation.
3758 ( navKeys . length === 1 ? sideNavigation [ 0 ] [ 1 ] . items : sideNavigation ) . map (
38- ( [ , { label, items } ] ) => ( {
59+ ( [ , { label, items } ] : [ string , MappedItem ] ) => ( {
3960 groupName : label ,
40- items : items . map ( ( [ , item ] ) => item ) ,
61+ items : items ? items . map ( mapItem ) : [ ] ,
4162 } )
4263 ) ;
4364
0 commit comments