Skip to content

Commit

Permalink
Merge pull request rust-lang#1934 from killercup/feature/docs-version…
Browse files Browse the repository at this point in the history
…-ordering

Docs index: Sort versions in a nice way
  • Loading branch information
oli-obk authored Aug 7, 2017
2 parents cc5d106 + 02f2035 commit 681a303
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions util/gh-pages/versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ <h3 class="panel-title">
</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>
Expand All @@ -54,6 +54,22 @@ <h3 class="panel-title">
.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;
Expand Down

0 comments on commit 681a303

Please sign in to comment.