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>
|
</div>
|
||||||
|
|
||||||
<ul class="list-group">
|
<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">
|
href="./{{version}}/index.html">
|
||||||
{{version}}
|
{{normalizeVersion(version)}}
|
||||||
</a>
|
</a>
|
||||||
</ul>
|
</ul>
|
||||||
</article>
|
</article>
|
||||||
|
@ -54,6 +54,22 @@
|
||||||
.controller('docVersions', function ($scope, $http) {
|
.controller('docVersions', function ($scope, $http) {
|
||||||
$scope.loading = true;
|
$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')
|
$http.get('./versions.json')
|
||||||
.success(function (data) {
|
.success(function (data) {
|
||||||
$scope.data = data;
|
$scope.data = data;
|
||||||
|
|
Loading…
Reference in a new issue