diff --git a/.agents/skills/publishing-docs-versions/SKILL.md b/.agents/skills/publishing-docs-versions/SKILL.md index 55a5a7ac4..ac0d03468 100644 --- a/.agents/skills/publishing-docs-versions/SKILL.md +++ b/.agents/skills/publishing-docs-versions/SKILL.md @@ -20,10 +20,12 @@ Use this skill for the Sourcegraph docs repo release-version workflow: cutting l - `src/data/versions.ts` - `docs/legacy.mdx` - `src/data/versions.ts` on `origin/main` is the canonical dropdown list. The - current site exposes it through `/docs/api/versions`, and legacy selectors - load that manifest at runtime. + current site exposes it through `https://sourcegraph.com/docs/api/versions`, + and legacy selectors load that manifest at runtime. - A legacy branch's bundled `src/data/versions.ts` is only a fallback. Its first entry identifies the archived site and must not have the `latest` label. +- A legacy selector shows the current latest version, its selected archived + version, and older versions. It omits versions between latest and selected. ## Standard workflow for a new release diff --git a/src/components/VersionSelector.tsx b/src/components/VersionSelector.tsx index 90b34b93c..708444a0e 100644 --- a/src/components/VersionSelector.tsx +++ b/src/components/VersionSelector.tsx @@ -27,6 +27,23 @@ function isVersion(value: unknown): value is VersionI { ); } +function versionsForSite(remoteVersions: VersionI[]): VersionI[] { + const selectedIndex = remoteVersions.findIndex( + version => version.name === versions[0].name + ); + + if (selectedIndex === 0) return remoteVersions; + if (selectedIndex > 0) { + return [remoteVersions[0], ...remoteVersions.slice(selectedIndex)]; + } + + return [ + remoteVersions[0], + {...versions[0], label: undefined}, + ...versions.slice(1) + ]; +} + export default function VersionSelector() { const path = usePathname(); const [availableVersions, setAvailableVersions] = @@ -57,16 +74,7 @@ export default function VersionSelector() { return; } - setAvailableVersions( - remoteVersions.some( - version => version.name === versions[0].name - ) - ? remoteVersions - : [ - ...remoteVersions, - {...versions[0], label: undefined} - ] - ); + setAvailableVersions(versionsForSite(remoteVersions)); }) .catch(() => { // Keep this build's version list if the current site is unavailable.