@@ -32,7 +32,7 @@ function getSortValue(
3232 prop : string ,
3333 docs : Map < string , SidebarItemsGeneratorDoc > ,
3434 item : NormalizedSidebarItem
35- ) : string | number {
35+ ) : string | number | undefined {
3636 if ( prop in item ) {
3737 return item [ prop ] ;
3838 }
@@ -76,8 +76,8 @@ function getSortValue(
7676 }
7777 }
7878
79- console . warn ( `Could not get sort prop '${ prop } ' on sidebar item` , item ) ;
80- return "" ;
79+ // console.warn(`Could not get sort prop '${prop}' on sidebar item`, item);
80+ return undefined ;
8181}
8282
8383const config : Config = {
@@ -115,8 +115,12 @@ const config: Config = {
115115 const sidebarItems = await defaultSidebarItemsGenerator ( args ) ;
116116
117117 if ( Array . isArray ( args . item . customProps ?. [ "sort" ] ) ) {
118- const ascending = args . item . customProps ?. [ "sort" ] [ 1 ] !== "desc" ;
119- const prop = args . item . customProps ?. [ "sort" ] [ 0 ] ;
118+ let props = args . item . customProps ?. [ "sort" ] as
119+ | [ string , string ]
120+ | [ string , string ] [ ] ;
121+ if ( ! Array . isArray ( props [ 0 ] ) ) {
122+ props = [ props as [ string , string ] ] ;
123+ }
120124
121125 const docsLookup = new Map < string , SidebarItemsGeneratorDoc > (
122126 args . docs . map ( ( d ) => [ d . id , d ] )
@@ -125,27 +129,45 @@ const config: Config = {
125129 // Reverse items in categories
126130
127131 sidebarItems . sort ( ( a , b ) => {
128- let av = getSortValue ( prop , docsLookup , a ) ;
129- let bv = getSortValue ( prop , docsLookup , b ) ;
132+ for ( const prop of props ) {
133+ const ascending = prop [ 1 ] !== "desc" ;
130134
131- if ( typeof av !== typeof bv ) {
132- av = String ( av ) ;
133- bv = String ( bv ) ;
134- }
135+ let av = getSortValue ( prop [ 0 ] , docsLookup , a ) ;
136+ let bv = getSortValue ( prop [ 0 ] , docsLookup , b ) ;
135137
136- if ( typeof av === "string" ) {
137- if ( ascending ) {
138- return av . localeCompare ( bv as string ) ;
139- } else {
140- return ( bv as string ) . localeCompare ( av ) ;
138+ if ( typeof av !== typeof bv ) {
139+ av = av === undefined ? av : String ( av ) ;
140+ bv = bv === undefined ? bv : String ( bv ) ;
141141 }
142- } else {
143- if ( ascending ) {
144- return av - ( bv as number ) ;
142+
143+ var result = 0 ;
144+
145+ if ( av === undefined && bv === undefined ) {
146+ // continue
147+ } else if ( av === undefined ) {
148+ return - 1 ;
149+ } else if ( bv === undefined ) {
150+ return 1 ;
151+ } else if ( typeof av === "string" ) {
152+ if ( ascending ) {
153+ result = av . localeCompare ( bv as string ) ;
154+ } else {
155+ result = ( bv as string ) . localeCompare ( av ) ;
156+ }
145157 } else {
146- return ( bv as number ) - av ;
158+ if ( ascending ) {
159+ result = av - ( bv as number ) ;
160+ } else {
161+ result = ( bv as number ) - av ;
162+ }
163+ }
164+
165+ if ( result !== 0 ) {
166+ return result ;
147167 }
148168 }
169+
170+ return 0 ;
149171 } ) ;
150172 }
151173
@@ -319,16 +341,14 @@ const config: Config = {
319341 const sassLoader = sassRule ! . use [ sassLoaderIndex ] as RuleSetRule ;
320342 sassLoader . options = {
321343 ...( ( sassLoader . options as object | undefined ) ?? { } ) ,
322- sourceMap : true // force sourcemaps
344+ sourceMap : true , // force sourcemaps
323345 } ;
324346
325-
326347 // insert resolve-url-loader before SASS loader to fix relative URLs
327348 sassRule ! . use . splice ( sassLoaderIndex , 0 , {
328349 loader : "resolve-url-loader" ,
329350 } ) ;
330351
331-
332352 return {
333353 plugins : [
334354 // Copy the Font and SoundFont Files to the output
0 commit comments