-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daf247c
commit 276f494
Showing
2 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
angular.module('gcloud.docs') | ||
.factory('getLinks', function(pages) { | ||
.factory('getLinks', function(versions, pages) { | ||
'use strict'; | ||
|
||
// `version` is the current version being browsed. | ||
return function(version) { | ||
var baseUrl = '#/docs/' + version; | ||
var VERSIONS = pages.VERSIONS; | ||
var versions; | ||
var match; | ||
if (!version || version === 'master') { | ||
versions = Object.keys(VERSIONS); | ||
match = versions[versions.length - 1]; | ||
} else { | ||
match = Object.keys(VERSIONS).filter(semver.satisfies.bind(null, version))[0]; | ||
|
||
if (version === 'master') { | ||
// Use the most recent release. | ||
version = versions[0]; | ||
} | ||
return VERSIONS[match] | ||
.map(function(module) { | ||
if (pages[module]._url) { | ||
pages[module].url = pages[module]._url.replace('{baseUrl}', baseUrl); | ||
|
||
// Use semver matching to put all matching modules together. | ||
return Object.keys(VERSIONS) | ||
.reduce(function(acc, potentialVersion) { | ||
if (semver.satisfies(version, potentialVersion)) { | ||
acc = acc.concat(VERSIONS[potentialVersion].map(function(module) { | ||
if (pages[module]._url) { | ||
pages[module].url = pages[module]._url.replace('{baseUrl}', baseUrl); | ||
} | ||
return pages[module]; | ||
})); | ||
} | ||
return pages[module]; | ||
return acc; | ||
}, []) | ||
.sort(function(moduleA, moduleB) { | ||
// A title matching `gcloud` will come first in the list. | ||
return moduleA.title === 'gcloud' ? -1 : moduleA.title > moduleB.title; | ||
}); | ||
}; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters