mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 15:05:50 +00:00
FIX Ensure changelogs are sorted correctly.
This commit is contained in:
parent
6fe74b1fd8
commit
7ffdc5305d
@ -1,10 +1,40 @@
|
||||
import { SilverstripeDocument } from "../types";
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Validates whether a given string looks like a semantic versioning number
|
||||
*/
|
||||
function isVersionNumber(value: string): boolean {
|
||||
return /^\d+\.\d+\.\d+(-(alpha|beta|rc)\d*)?$/.test(value);
|
||||
}
|
||||
|
||||
const sortFiles = (a: SilverstripeDocument, b: SilverstripeDocument): number => {
|
||||
if (a.isIndex !== b.isIndex) {
|
||||
//return a.isIndex ? -1 : 1;
|
||||
}
|
||||
return a.fileAbsolutePath > b.fileAbsolutePath ? 1 : -1;
|
||||
|
||||
let compA = a.fileAbsolutePath;
|
||||
let compB = b.fileAbsolutePath;
|
||||
const compareOptions = {
|
||||
numeric: false,
|
||||
sensitivity: 'case',
|
||||
};
|
||||
|
||||
// Only apply special comparison logic for files in the same directory
|
||||
if (path.dirname(a.fileAbsolutePath) === path.dirname(b.fileAbsolutePath)) {
|
||||
// Compare numbers and version numbers numerically
|
||||
if (
|
||||
(!isNaN(a.fileTitle) && !isNaN(b.fileTitle))
|
||||
|| (isVersionNumber(a.fileTitle) && isVersionNumber(a.fileTitle))
|
||||
) {
|
||||
// compare numerically
|
||||
compA = a.fileTitle;
|
||||
compB = b.fileTitle;
|
||||
compareOptions.numeric = true;
|
||||
}
|
||||
}
|
||||
|
||||
return compA.localeCompare(compB, 'en', compareOptions);
|
||||
};
|
||||
|
||||
export default sortFiles;
|
Loading…
x
Reference in New Issue
Block a user