Skip to content

Commit

Permalink
docs: dynamical URLs in API docs navigation links.
Browse files Browse the repository at this point in the history
Previously the API docs navigation links displayed on to the left on
/:language/docs/ had `v4.x` and `v6.x` hardcoded in their URL.

These changes fixes that by using the actual LTS/current major versions
based on the https://nodejs.org/download/release/index.json.
  • Loading branch information
phillipj authored and jasnell committed Oct 25, 2016
1 parent 14805d5 commit 55012f3
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions locale/de/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/en/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/es/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/it/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/ja/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"text": "よくある質問"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/ko/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/uk/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
4 changes: 2 additions & 2 deletions locale/zh-cn/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"text": "FAQ"
},
"api-lts": {
"link": "/dist/latest-v4.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"subtext": "LTS",
"text": "%ver% API"
},
"api-current": {
"link": "/dist/latest-v6.x/docs/api",
"link": "/dist/latest-%ver-major%/docs/api",
"text": "%ver% API"
},
"guides": {
Expand Down
5 changes: 5 additions & 0 deletions scripts/helpers/latestversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const semver = require('semver')

const map = (release) => release && {
node: release.version,
nodeMajor: majorStr(release),
npm: release.npm,
v8: release.v8,
openssl: release.openssl
Expand All @@ -15,3 +16,7 @@ exports.current = (releases) => {
}

exports.lts = (releases) => map(releases.find((release) => release.lts))

function majorStr (release) {
return `v${semver.major(release.version)}.x`
}
2 changes: 2 additions & 0 deletions scripts/plugins/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ module.exports = function buildNavigation (latestVersions) {
// Insert latest versions for API docs
if (key === 'api-current') {
obj[key].text = obj[key].text.replace(/%ver%/, latestVersions.current.node)
obj[key].link = obj[key].link.replace(/%ver-major%/, latestVersions.current.nodeMajor)
}
if (key === 'api-lts') {
obj[key].text = obj[key].text.replace(/%ver%/, latestVersions.lts.node)
obj[key].link = obj[key].link.replace(/%ver-major%/, latestVersions.lts.nodeMajor)
}

meta.nav[level] = meta.nav[level] || parent
Expand Down
11 changes: 10 additions & 1 deletion tests/scripts/latestversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const test = require('tape')
const latestversion = require('../../scripts/helpers/latestversion')

test('latestversion.current()', (t) => {
t.test('should be greater equal/greater than v5.0.0', (t) => {
t.test('should be equal/greater than v5.0.0', (t) => {
const currentVersion = latestversion.current([
{ version: 'v4.2.1', lts: true },
{ version: 'v0.12.7', lts: false }
Expand All @@ -26,6 +26,15 @@ test('latestversion.current()', (t) => {
t.end()
})

t.test('should generate major version string', (t) => {
const currentVersion = latestversion.current([
{ version: 'v7.0.0', lts: false }
])

t.equal(currentVersion.nodeMajor, 'v7.x')
t.end()
})

t.end()
})

Expand Down

0 comments on commit 55012f3

Please sign in to comment.