-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows staying on the same page when switching to a version that contains the same page. Closes gh-269
- Loading branch information
Showing
4 changed files
with
122 additions
and
9 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
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,21 +1,42 @@ | ||
'use strict' | ||
|
||
module.exports = (components) => versionTree(components) | ||
module.exports = (components, page) => versionTree(components, page) | ||
|
||
function versionTree (components) { | ||
function versionTree (components, page) { | ||
const versionToUrl = {} | ||
if (page && page.versions) { | ||
page.versions.forEach((v) => { | ||
versionToUrl[v.displayVersion] = v.url | ||
}) | ||
} | ||
for (const [, component] of Object.entries(components)) { | ||
component.versionTree = splitVersions(component.versions) | ||
const componentVersionToUrl = component && | ||
page && | ||
page.component && | ||
component.name === page.component.name ? versionToUrl : {} | ||
component.versionTree = splitVersions(component.versions, componentVersionToUrl) | ||
} | ||
return components | ||
} | ||
|
||
function splitVersions (versions) { | ||
const snapshot = versions.filter((v) => v.displayVersion.includes('SNAPSHOT')) | ||
const stable = versions.filter((v) => !v.displayVersion.includes('-')) | ||
const preview = versions.filter((v) => !snapshot.includes(v) && !stable.includes(v)) | ||
function splitVersions (versions, versionToUrl) { | ||
const snapshot = versions.filter((v) => v.displayVersion.includes('SNAPSHOT')).map((v) => navVersion(v, versionToUrl)) | ||
const stable = versions.filter((v) => !v.displayVersion.includes('-')).map((v) => navVersion(v, versionToUrl)) | ||
const preview = versions.filter((v) => !v.displayVersion.includes('SNAPSHOT') && | ||
v.displayVersion.includes('-')).map((v) => navVersion(v, versionToUrl)) | ||
return { | ||
snapshot: snapshot.length > 0 ? snapshot : null, | ||
stable: stable.length > 0 ? stable : null, | ||
preview: preview.length > 0 ? preview : null, | ||
} | ||
} | ||
|
||
function navVersion (v, versionToUrl) { | ||
const navVersion = | ||
v.latest ? { latest: v.latest, url: v.url, displayVersion: v.displayVersion } | ||
: { url: v.url, displayVersion: v.displayVersion } | ||
if (versionToUrl[v.displayVersion]) { | ||
navVersion.url = versionToUrl[v.displayVersion] | ||
} | ||
return navVersion | ||
} |
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
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