Skip to content

Commit a894fb4

Browse files
committed
version selector
1 parent 24c9744 commit a894fb4

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@clack/prompts": "^0.11.0",
4646
"@heroicons/react": "^2.2.0",
4747
"@node-core/rehype-shiki": "1.0.1-1ccb8ae3260e261531c3f44674b8a98ff8918c30",
48-
"@node-core/ui-components": "1.0.1-76b9440b92d63dfcc72150e14795f6958c55c2ce",
48+
"@node-core/ui-components": "1.0.1-0bb5d49b96e1f11e1ef6cf965861929693053ca6",
4949
"@orama/orama": "^3.1.7",
5050
"@orama/plugin-data-persistence": "^3.1.7",
5151
"@orama/react-components": "^0.8.0",

src/generators/jsx-ast/index.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { buildSideBarDocPages } from './utils/buildBarProps.mjs';
22
import buildContent from './utils/buildContent.mjs';
33
import {
44
getCompatibleVersions,
5+
getVersionFromSemVer,
6+
getVersionURL,
57
groupNodesByModule,
68
} from '../../utils/generators.mjs';
79
import { getRemarkRecma } from '../../utils/remark.mjs';
@@ -48,7 +50,13 @@ export default {
4850
);
4951

5052
const sideBarProps = {
51-
versions: versions.map(({ version }) => `v${version.version}`),
53+
versions: versions.map(({ version }) => {
54+
const parsed = getVersionFromSemVer(version);
55+
return {
56+
value: getVersionURL(parsed, entry.api),
57+
label: `v${parsed}`,
58+
};
59+
}),
5260
currentVersion: `v${version.version}`,
5361
docPages,
5462
};

src/generators/legacy-html/utils/buildDropdowns.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
'use strict';
22

3-
import {
4-
DOC_API_BASE_URL_VERSION,
5-
DOC_API_BLOB_EDIT_BASE_URL,
6-
} from '../../../constants.mjs';
3+
import { DOC_API_BLOB_EDIT_BASE_URL } from '../../../constants.mjs';
74
import {
85
getCompatibleVersions,
96
getVersionFromSemVer,
7+
getVersionURL,
108
} from '../../../utils/generators.mjs';
119

1210
/**
@@ -63,9 +61,8 @@ const buildVersions = (api, added, versions) => {
6361
const parsedVersion = getVersionFromSemVer(version);
6462

6563
const ltsLabel = isLts ? '<b>LTS</b>' : '';
66-
const linkToApi = `${DOC_API_BASE_URL_VERSION}${parsedVersion}/api/${api}.html`;
6764

68-
return `<li><a href="${linkToApi}">${parsedVersion} ${ltsLabel}</a></li>`;
65+
return `<li><a href="${getVersionURL(parsedVersion, api)}">${parsedVersion} ${ltsLabel}</a></li>`;
6966
});
7067

7168
return (

src/generators/web/client/components/SideBar.jsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Select from '@node-core/ui-components/Common/Select/index.js';
12
import SideBar from '@node-core/ui-components/Containers/SideBar';
23
import { useEffect, useState } from 'react';
34

@@ -25,17 +26,21 @@ const getCurrentDoc = () => {
2526
return filename + hash;
2627
};
2728

29+
/**
30+
* Redirect to a URL
31+
* @param {string} url URL
32+
*/
33+
const redirect = url => (window.location.href = url);
34+
2835
/**
2936
* Sidebar component for MDX documentation with version selection and page navigation
3037
* @param {SideBarProps} props - Component props
31-
* @param {Array<string>} props.versions - Available documentation versions
38+
* @param {Array<{ value: string, label: string }>} props.versions - Available documentation versions
3239
* @param {string} props.currentVersion - Currently selected version
3340
* @param {Array<DocPage>} props.docPages - Documentation pages structure
3441
* @returns {JSX.Element} The rendered sidebar component
3542
*/
36-
export default function DocumentationSideBar({
37-
/* versions, currentVersion, */ docPages,
38-
}) {
43+
export default ({ versions, currentVersion, docPages }) => {
3944
const [pathname, setPathname] = useState(CLIENT ? getCurrentDoc() : '');
4045

4146
useEffect(() => {
@@ -54,12 +59,15 @@ export default function DocumentationSideBar({
5459
}));
5560

5661
return (
57-
<SideBar
58-
pathname={pathname}
59-
groups={groups}
60-
onSelect={url => {
61-
window.location.href = url;
62-
}}
63-
/>
62+
<SideBar pathname={pathname} groups={groups} onSelect={redirect}>
63+
<div>
64+
<Select
65+
label="Node.js version"
66+
values={versions}
67+
placeholder={currentVersion}
68+
onChange={redirect}
69+
/>
70+
</div>
71+
</SideBar>
6472
);
65-
}
73+
};

src/utils/generators.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { coerce, compare, major } from 'semver';
44

5+
import { DOC_API_BASE_URL_VERSION } from '../constants.mjs';
6+
57
/**
68
* Groups all the API metadata nodes by module (`api` property) so that we can process each different file
79
* based on the module it belongs to.
@@ -33,6 +35,15 @@ export const getVersionFromSemVer = version =>
3335
? `${version.major}.x`
3436
: `${version.major}.${version.minor}.x`;
3537

38+
/**
39+
* Gets the documentation URL for an API and version
40+
*
41+
* @param {string} version The version to be parsed
42+
* @param {string} api The document
43+
*/
44+
export const getVersionURL = (version, api) =>
45+
`${DOC_API_BASE_URL_VERSION}${version}/api/${api}.html`;
46+
3647
/**
3748
* @TODO: This should not be necessary, and indicates errors within the API docs
3849
* @TODO: Hookup into a future Validation/Linting API

0 commit comments

Comments
 (0)