Skip to content

Commit 9917742

Browse files
docs: re-structure versioning.
1 parent daf247c commit 9917742

2 files changed

Lines changed: 52 additions & 16 deletions

File tree

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
angular.module('gcloud.docs')
2-
.factory('getLinks', function(pages) {
2+
.factory('getLinks', function(versions, pages) {
33
'use strict';
44

5+
// `version` is the current version being browsed.
56
return function(version) {
67
var baseUrl = '#/docs/' + version;
78
var VERSIONS = pages.VERSIONS;
8-
var versions;
9-
var match;
10-
if (!version || version === 'master') {
11-
versions = Object.keys(VERSIONS);
12-
match = versions[versions.length - 1];
13-
} else {
14-
match = Object.keys(VERSIONS).filter(semver.satisfies.bind(null, version))[0];
9+
10+
if (version === 'master') {
11+
// Use the most recent release.
12+
version = versions[0];
1513
}
16-
return VERSIONS[match]
17-
.map(function(module) {
18-
if (pages[module]._url) {
19-
pages[module].url = pages[module]._url.replace('{baseUrl}', baseUrl);
14+
15+
// Use semver matching to put all matching modules together.
16+
return Object.keys(VERSIONS)
17+
.reduce(function(acc, potentialVersion) {
18+
if (semver.satisfies(version, potentialVersion)) {
19+
acc = acc.concat(VERSIONS[potentialVersion].map(function(module) {
20+
if (pages[module]._url) {
21+
pages[module].url = pages[module]._url.replace('{baseUrl}', baseUrl);
22+
}
23+
return pages[module];
24+
}));
2025
}
21-
return pages[module];
26+
return acc;
27+
}, [])
28+
.sort(function(moduleA, moduleB) {
29+
// A title matching `gcloud` will come first in the list.
30+
return moduleA.title === 'gcloud' ? -1 : moduleA.title > moduleB.title;
2231
});
2332
};
2433
});

docs/components/docs/docs-values.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
angular.module('gcloud.docs')
22
.value('pages', {
3+
4+
//---------------------------------------------
5+
// Link schema:
6+
//---------------------------------------------
7+
// key: {
8+
// title: 'Display Name for Link',
9+
// _url: '{baseUrl}/module-name',
10+
//
11+
// pages: [
12+
// title: 'Display Name for Sub-Page Link',
13+
// url: '/path-relevant-to-parent-url'
14+
// ]
15+
// }
16+
//---------------------------------------------
17+
318
gcloud: {
419
title: 'gcloud',
520
_url: '{baseUrl}'
@@ -62,8 +77,20 @@ angular.module('gcloud.docs')
6277
VERSIONS: {
6378
// Give a version with/without a comparator, anything semver:
6479
// https://github.com/npm/node-semver#versions
65-
// List should be in ascending order.
66-
'<=0.7.1': ['gcloud', 'datastore', 'storage'],
67-
'>0.7.1': ['gcloud', 'datastoreWithTransaction', 'pubsub', 'storage']
80+
//
81+
// Multiple keys may be used to match a version.
82+
//
83+
// Example:
84+
// A user is browsing the docs for 0.7.0. If the list below contains the
85+
// keys: "*", ">0.4.0", and "0.7.0", all of the contents will be joined.
86+
//
87+
// Notes on ordering:
88+
// These are sorted alphabetically by `module`.title.
89+
//
90+
// To keep the documentation for the main module, `gcloud`, on top of the
91+
// link list, **make sure the title is `gcloud`**
92+
'*': ['gcloud', 'storage'],
93+
'<0.8.0': ['datastore'],
94+
'>=0.8.0': ['datastoreWithTransaction', 'pubsub']
6895
}
6996
});

0 commit comments

Comments
 (0)