mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 15:05:50 +00:00
Merge pull request #239 from creative-commoners/pulls/master/changelog-sort-order
FIX Ensure changelogs are sorted correctly.
This commit is contained in:
commit
305d41e073
@ -1,10 +1,40 @@
|
|||||||
import { SilverstripeDocument } from "../types";
|
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 => {
|
const sortFiles = (a: SilverstripeDocument, b: SilverstripeDocument): number => {
|
||||||
if (a.isIndex !== b.isIndex) {
|
if (a.isIndex !== b.isIndex) {
|
||||||
//return a.isIndex ? -1 : 1;
|
//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;
|
export default sortFiles;
|
Loading…
x
Reference in New Issue
Block a user