mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
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:
parent
cc5d1065fb
commit
02f2035389
1 changed files with 18 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue