@@ -149,46 +149,43 @@ export function Theme({pageMap, children}: ThemeProps) {
149149 { activeHeaderLink ? activeHeaderLink . title : siteTitle }
150150 </ Breadcrumbs . Item >
151151 ) }
152- { activePath . reduce ( ( acc , item , index , items ) => {
153- const nextItem = items [ index + 1 ]
152+ { activePath
153+ . filter ( ( item , index , array ) => {
154+ const nextItem = array [ index + 1 ]
154155
155- // Skip items in these cases:
156- // 1. When current item is a folder followed by its index page
157- // 2. When current item is an index page with a tab-label
158- if (
159- ( index < items . length - 1 &&
160- nextItem . name === 'index' &&
161- item . route === nextItem . route &&
162- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
163- ! nextItem . frontMatter ?. [ 'tab-label' ] ) ||
164- ( item . name === 'index' &&
165- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
166- item . frontMatter ?. [ 'tab-label' ] )
167- ) {
168- return acc
169- }
156+ // Skip when current item is a folder followed by its index page
157+ // or when it is an index page with a tabbed navigation
158+ return ! (
159+ ( index < array . length - 1 &&
160+ nextItem . name === 'index' &&
161+ item . route === nextItem . route &&
162+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
163+ ! nextItem . frontMatter ?. [ 'tab-label' ] ) ||
164+ ( item . name === 'index' &&
165+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
166+ item . frontMatter ?. [ 'tab-label' ] )
167+ )
168+ } )
169+ . map ( ( item , index , visibleItems ) => {
170+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
171+ const itemTitle = item . frontMatter ?. [ 'tab-label' ] || item . title
172+ const isLastItem = index === visibleItems . length - 1
170173
171- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
172- const itemTitle = item . frontMatter ?. [ 'tab-label' ] || item . title
173- const isLastItem = index === items . length - 1
174-
175- acc . push (
176- < Breadcrumbs . Item
177- as = { NextLink }
178- key = { item . name }
179- href = { item . route }
180- selected = { isLastItem }
181- sx = { {
182- textTransform : 'capitalize' ,
183- color : 'var(--brand-InlineLink-color-rest)' ,
184- } }
185- >
186- { itemTitle . replace ( / - / g, ' ' ) }
187- </ Breadcrumbs . Item > ,
188- )
189-
190- return acc
191- } , [ ] as React . ReactNode [ ] ) }
174+ return (
175+ < Breadcrumbs . Item
176+ as = { NextLink }
177+ key = { item . name }
178+ href = { item . route }
179+ selected = { isLastItem }
180+ sx = { {
181+ textTransform : 'capitalize' ,
182+ color : 'var(--brand-InlineLink-color-rest)' ,
183+ } }
184+ >
185+ { itemTitle . replace ( / - / g, ' ' ) }
186+ </ Breadcrumbs . Item >
187+ )
188+ } ) }
192189 </ Breadcrumbs >
193190 ) }
194191
0 commit comments