diff --git a/components/SideBar.jsx b/components/SideBar.jsx
index 725e5e57..ffa79547 100644
--- a/components/SideBar.jsx
+++ b/components/SideBar.jsx
@@ -1,27 +1,42 @@
+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);
const PrefetchLink = props => ;
+// The versioned API docs pass `sidebar` as an array of groups; the main site keys it by section.
+const isVersioned = Array.isArray(sidebar);
+
+// Versioned pages expose a version relative path, we prefix it so it matches the absolute sidebar links.
+const versionBase = isVersioned ? `/docs/api/v${version.major}.x` : '';
+
const pathnameFor = path => {
- const clean = path.replace(/\/index$/, '');
- if (!clean) return '/';
- return clean.startsWith('/') ? clean : `/${clean}`;
+ const clean = path.replace(/\/index$/, '').replace(/^\//, '');
+ return (clean ? `${versionBase}/${clean}` : versionBase) || '/';
};
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 ? versionBase : undefined;
+
+/** Docs sidebar, plus a webpack version picker on the versioned API docs. */
export default ({ metadata }) => (
(
onSelect={redirect}
as={PrefetchLink}
title="Navigation"
- />
+ >
+ {isVersioned && (
+
+
+
+ )}
+
);
diff --git a/scripts/markdown/governance.mjs b/scripts/markdown/governance.mjs
index 4e89d7b8..b47a6293 100644
--- a/scripts/markdown/governance.mjs
+++ b/scripts/markdown/governance.mjs
@@ -26,11 +26,14 @@ const FILE_MAP = {
'AI_POLICY.md': { output: 'ai-policy', label: 'AI Policy' },
};
+const pageLink = output =>
+ output === 'index' ? '/about/governance' : `/about/governance/${output}`;
+
// Derived from FILE_MAP - stays in sync automatically if entries are added/removed.
const LINK_REWRITE_MAP = Object.fromEntries(
Object.entries(FILE_MAP).map(([source, { output }]) => [
source,
- `/about/governance/${output}`,
+ pageLink(output),
])
);
@@ -77,7 +80,7 @@ const siteJson = {
{
groupName: 'Governance',
items: fetched.map(({ output, label }) => ({
- link: `/about/governance/${output}`,
+ link: pageLink(output),
label,
})),
},