File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " vocs " : patch
3+ ---
4+
5+ Enhanced sidebar active match mechanism to avoid duplicate topnav matches.
Original file line number Diff line number Diff line change @@ -9,15 +9,21 @@ function getActiveNavIds({
99 pathname : string
1010} ) : number [ ] {
1111 const path = pathname . replace ( / \. h t m l $ / , '' )
12- const activeIds = [ ]
12+ const matches : { id : number ; children : number [ ] } [ ] = [ ]
13+
1314 for ( const item of items ) {
14- if ( item . link && path . startsWith ( item . match || item . link ) ) activeIds . push ( item . id )
15+ if ( item . link && path . startsWith ( item . match || item . link ) )
16+ matches . push ( { id : item . id , children : [ ] } )
1517 else if ( item . items ) {
1618 const activeChildItems = getActiveNavIds ( { items : item . items , pathname } )
17- if ( activeChildItems . length > 0 ) activeIds . push ( item . id )
19+ if ( activeChildItems . length > 0 ) matches . push ( { id : item . id , children : activeChildItems } )
1820 }
1921 }
20- return activeIds
22+
23+ // Return only the last match and its children (prefer most specific/last match)
24+ if ( matches . length === 0 ) return [ ]
25+ const lastMatch = matches [ matches . length - 1 ]
26+ return [ lastMatch . id , ...lastMatch . children ]
2127}
2228
2329export function useActiveNavIds ( {
You can’t perform that action at this time.
0 commit comments