diff --git a/components/SideBar.jsx b/components/SideBar.jsx index 725e5e5..0d683f7 100644 --- a/components/SideBar.jsx +++ b/components/SideBar.jsx @@ -1,5 +1,9 @@ +import Select from '@node-core/ui-components/Common/Select'; import SideBar from '@node-core/ui-components/Containers/Sidebar'; +import { major } from 'semver'; import { sidebar } from '#theme/local/site'; +import { version } from '#theme/config'; +import versions from '../versions.json' with { type: 'json' }; /** @param {string} url */ const redirect = url => (window.location.href = url); @@ -12,16 +16,27 @@ const pathnameFor = path => { return clean.startsWith('/') ? clean : `/${clean}`; }; +// The versioned API docs pass `sidebar` as an array of groups; the main site keys it by section. +const isVersioned = Array.isArray(sidebar); + const groupsFor = path => { - if (Array.isArray(sidebar)) return sidebar; + if (isVersioned) return sidebar; const segment = path.split('/').filter(Boolean)[0]; return sidebar[segment] ?? []; }; -/** - * Sidebar component for MDX documentation with page navigation. - */ +const versionItems = versions.map(version => ({ + value: `/docs/api/v${major(version)}.x`, + label: `v${major(version)}.x`, +})); + +// Preselect the picker with the version this API build was generated for. +const currentVersion = isVersioned + ? `/docs/api/v${version.major}.x` + : undefined; + +/** Docs sidebar, plus a webpack version picker on the versioned API docs. */ export default ({ metadata }) => ( ( onSelect={redirect} as={PrefetchLink} title="Navigation" - /> + > + {isVersioned && ( +
+