summary refs log tree commit diff
diff options
context:
space:
mode:
authorerikjohnston <erikjohnston@users.noreply.github.com>2024-03-14 15:21:11 +0000
committererikjohnston <erikjohnston@users.noreply.github.com>2024-03-14 15:21:11 +0000
commit88f9c0a75f79fbb4086a215275e576ce8a0575c8 (patch)
tree809339d2332f868e88cc6de73cbb7893f1cec837
parentdeploy: acc2f00ecaab073abd8bc386d0b4f0d8b30606ef (diff)
downloadsynapse-88f9c0a75f79fbb4086a215275e576ce8a0575c8.tar.xz
deploy: 1198f649ea91bcc21ae5b596ad50bf1851de2589
-rw-r--r--develop/docs/website_files/version-picker.js26
-rw-r--r--develop/website_files/version-picker.js26
2 files changed, 46 insertions, 6 deletions
diff --git a/develop/docs/website_files/version-picker.js b/develop/docs/website_files/version-picker.js
index b6f35f29c7..3174b5d0bc 100644
--- a/develop/docs/website_files/version-picker.js
+++ b/develop/docs/website_files/version-picker.js
@@ -100,10 +100,30 @@ function sortVersions(a, b) {
     if (a === 'develop' || a === 'latest') return -1;
     if (b === 'develop' || b === 'latest') return 1;
 
-    const versionA = (a.match(/v\d+(\.\d+)+/) || [])[0];
-    const versionB = (b.match(/v\d+(\.\d+)+/) || [])[0];
+    // If any of the versions do not confrom to a semantic version string, they
+    // 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;
 }
 
 /**
diff --git a/develop/website_files/version-picker.js b/develop/website_files/version-picker.js
index b6f35f29c7..3174b5d0bc 100644
--- a/develop/website_files/version-picker.js
+++ b/develop/website_files/version-picker.js
@@ -100,10 +100,30 @@ function sortVersions(a, b) {
     if (a === 'develop' || a === 'latest') return -1;
     if (b === 'develop' || b === 'latest') return 1;
 
-    const versionA = (a.match(/v\d+(\.\d+)+/) || [])[0];
-    const versionB = (b.match(/v\d+(\.\d+)+/) || [])[0];
+    // If any of the versions do not confrom to a semantic version string, they
+    // 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;
 }
 
 /**