From: Pascal Hertleif Date: Mon, 7 Aug 2017 10:57:17 +0000 (+0200) Subject: Docs index: Sort versions in a nice way X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=02f20353899fc061fa2a3f93a3202d0d00b673b3;p=rust.git 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".) --- diff --git a/util/gh-pages/versions.html b/util/gh-pages/versions.html index baa44bf4676..310a3873691 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;