File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change 1010
1111< script >
1212document . addEventListener ( 'DOMContentLoaded' , function ( ) {
13- // Only sort on reference pages
1413 if ( window . location . pathname . includes ( '/reference/' ) ) {
1514 const navContainer = document . querySelector ( '#bd-docs-nav .bd-toc-item' ) ;
1615 if ( navContainer ) {
17- const lists = navContainer . querySelectorAll ( 'ul' ) ;
16+ const topLevelItems = Array . from ( navContainer . children ) ;
1817
19- lists . forEach ( list => {
20- const items = Array . from ( list . children ) ;
21-
22- // Sort items alphabetically
23- items . sort ( ( a , b ) => {
24- const textA = a . textContent . trim ( ) . toLowerCase ( ) ;
25- const textB = b . textContent . trim ( ) . toLowerCase ( ) ;
26- return textA . localeCompare ( textB ) ;
18+ topLevelItems . forEach ( section => {
19+ const subLists = section . querySelectorAll ( 'ul' ) ;
20+ subLists . forEach ( list => {
21+ const items = Array . from ( list . children ) ;
22+
23+ items . sort ( ( a , b ) => {
24+ const textA = a . textContent . trim ( ) . toLowerCase ( ) ;
25+ const textB = b . textContent . trim ( ) . toLowerCase ( ) ;
26+ return textA . localeCompare ( textB ) ;
27+ } ) ;
28+
29+ items . forEach ( item => list . appendChild ( item ) ) ;
2730 } ) ;
28-
29- // Reattach sorted items
30- items . forEach ( item => list . appendChild ( item ) ) ;
3131 } ) ;
3232 }
3333 }
You can’t perform that action at this time.
0 commit comments