]> git.lizzy.rs Git - rust.git/commitdiff
Docs index: Sort versions in a nice way
authorPascal Hertleif <killercup@gmail.com>
Mon, 7 Aug 2017 10:57:17 +0000 (12:57 +0200)
committerPascal Hertleif <killercup@gmail.com>
Mon, 7 Aug 2017 11:00:43 +0000 (13:00 +0200)
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".)

util/gh-pages/versions.html

index baa44bf4676ddeb68e1d5ac28fa97c9c2ad06f6c..310a38736910bffa05d67fdff2dcd0cee1e9eac6 100644 (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>
         .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;