mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Sort versions in the documentation version picker appropriately. (#16966)
Fixes #16964 This adds a proper sorter for versions which takes into account semantic versions, rather than just relying on localeCompare.
This commit is contained in:
parent
acc2f00eca
commit
1198f649ea
1
changelog.d/16966.doc
Normal file
1
changelog.d/16966.doc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix the sort order for the documentation version picker, so that newer releases appear above older ones.
|
@ -100,10 +100,30 @@ function sortVersions(a, b) {
|
|||||||
if (a === 'develop' || a === 'latest') return -1;
|
if (a === 'develop' || a === 'latest') return -1;
|
||||||
if (b === 'develop' || b === 'latest') return 1;
|
if (b === 'develop' || b === 'latest') return 1;
|
||||||
|
|
||||||
const versionA = (a.match(/v\d+(\.\d+)+/) || [])[0];
|
// If any of the versions do not confrom to a semantic version string, they
|
||||||
const versionB = (b.match(/v\d+(\.\d+)+/) || [])[0];
|
// will be sorted behind a valid version.
|
||||||
|
const versionA = (a.match(/v(\d+(\.\d+)+)/) || [])[1]?.split('.') ?? '';
|
||||||
|
const versionB = (b.match(/v(\d+(\.\d+)+)/) || [])[1]?.split('.') ?? '';
|
||||||
|
|
||||||
return versionB.localeCompare(versionA);
|
for (let i = 0; i < Math.max(versionA.length, versionB.length); i++) {
|
||||||
|
if (versionB[i] === undefined) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (versionA[i] === undefined) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const partA = parseInt(versionA[i], 10);
|
||||||
|
const partB = parseInt(versionB[i], 10);
|
||||||
|
|
||||||
|
if (partA > partB) {
|
||||||
|
return -1;
|
||||||
|
} else if (partB > partA) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user