Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .agents/skills/publishing-docs-versions/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 18 additions & 10 deletions src/components/VersionSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -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.
Expand Down