From 02f20353899fc061fa2a3f93a3202d0d00b673b3 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Mon, 7 Aug 2017 12:57:17 +0200 Subject: [PATCH] Docs index: Sort versions in a nice way This introduces a very sophisticated algorithm to determine the ordering of versions on the rendered docs' start page. (Spoiler alert: It maps "master" and "current" to the largest possible float values and converts a version like "1.2.3" to "1002003".) --- util/gh-pages/versions.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/util/gh-pages/versions.html b/util/gh-pages/versions.html index baa44bf46..310a38736 100644 --- a/util/gh-pages/versions.html +++ b/util/gh-pages/versions.html @@ -34,9 +34,9 @@ @@ -54,6 +54,22 @@ .controller('docVersions', function ($scope, $http) { $scope.loading = true; + $scope.normalizeVersion = function(v) { + return v.replace(/^v/, ''); + }; + + $scope.versionOrder = function(v) { + if (v === 'master') { return Infinity; } + if (v === 'current') { return Number.MAX_VALUE; } + + return $scope.normalizeVersion(v) + .split('.') + .reverse() + .reduce(function(acc, val, index) { + return acc + (val * Math.pow(100, index)); + }, 0); + } + $http.get('./versions.json') .success(function (data) { $scope.data = data;