File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,30 @@ function processFolder(folder, parentSlug = '') {
120120 }
121121 } ) ;
122122
123+ // Sort items
124+ items . sort ( ( a , b ) => {
125+ // Get sort values, default to Infinity for items without sort value
126+ const aHasSort = 'sort' in a ;
127+ const bHasSort = 'sort' in b ;
128+
129+ // If one has sort and the other doesn't, sorted items come first
130+ if ( aHasSort !== bHasSort ) {
131+ return aHasSort ? - 1 : 1 ;
132+ }
133+
134+ // If both have sort values or both don't
135+ if ( aHasSort && bHasSort ) {
136+ const aSort = parseInt ( a . sort ) ;
137+ const bSort = parseInt ( b . sort ) ;
138+ if ( aSort !== bSort ) {
139+ return aSort - bSort ;
140+ }
141+ }
142+
143+ // Finally sort alphabetically by title
144+ return a . title . toLowerCase ( ) . localeCompare ( b . title . toLowerCase ( ) ) ;
145+ } ) ;
146+
123147 let result = {
124148 ...folderMetadata ,
125149 title : folderMetadata . title || folderName ,
You can’t perform that action at this time.
0 commit comments