Skip to content

Commit 8265acc

Browse files
committed
added sorting
1 parent eda31a8 commit 8265acc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

build-docs.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)