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".)
This commit is contained in:
Pascal Hertleif 2017-08-07 12:57:17 +02:00
parent cc5d1065fb
commit 02f2035389

View file

@ -34,9 +34,9 @@
</div>
<ul class="list-group">
<a class="list-group-item" ng-repeat="version in data | orderBy"
<a class="list-group-item" ng-repeat="version in data | orderBy:versionOrder:true"
href="./{{version}}/index.html">
{{version}}
{{normalizeVersion(version)}}
</a>
</ul>
</article>
@ -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;