mirror of
https://github.com/litruv/Docs-Viewer.git
synced 2026-07-24 02:36:07 +10:00
added sorting
This commit is contained in:
@@ -120,6 +120,30 @@ function processFolder(folder, parentSlug = '') {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sort items
|
||||||
|
items.sort((a, b) => {
|
||||||
|
// Get sort values, default to Infinity for items without sort value
|
||||||
|
const aHasSort = 'sort' in a;
|
||||||
|
const bHasSort = 'sort' in b;
|
||||||
|
|
||||||
|
// If one has sort and the other doesn't, sorted items come first
|
||||||
|
if (aHasSort !== bHasSort) {
|
||||||
|
return aHasSort ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If both have sort values or both don't
|
||||||
|
if (aHasSort && bHasSort) {
|
||||||
|
const aSort = parseInt(a.sort);
|
||||||
|
const bSort = parseInt(b.sort);
|
||||||
|
if (aSort !== bSort) {
|
||||||
|
return aSort - bSort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally sort alphabetically by title
|
||||||
|
return a.title.toLowerCase().localeCompare(b.title.toLowerCase());
|
||||||
|
});
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
...folderMetadata,
|
...folderMetadata,
|
||||||
title: folderMetadata.title || folderName,
|
title: folderMetadata.title || folderName,
|
||||||
|
|||||||
Reference in New Issue
Block a user