Skip to content

Support version switcher on versioned docs #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 16 additions & 7 deletions src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@ const VersionSwitcher = ({ isOpen, setIsOpen }) => {

if (typeof window === "undefined") return null;
if (!versions) return null;
if (!location.pathname.startsWith("/platform-enterprise/")) return null;

if (!location.pathname.startsWith("/platform-enterprise")) return null;

const items = versions.filter(
(version) => version.label !== currentVersion.label,
(version) => version.label !== currentVersion?.label,
);

// Extract the part of the URL after the current version
const currentVersionPrefix = `/platform-enterprise/${currentVersion.label}`;
const urlSuffix = location.pathname.replace(currentVersionPrefix, "");
let urlSuffix = "";

if (
currentVersion &&
location.pathname.startsWith(`/platform-enterprise/${currentVersion.label}`)
) {
const currentVersionPrefix = `/platform-enterprise/${currentVersion.label}`;
urlSuffix = location.pathname.replace(currentVersionPrefix, "");
}

return (
<>
Expand All @@ -58,8 +65,10 @@ const VersionSwitcher = ({ isOpen, setIsOpen }) => {
ref={dropdownRef}
>
<span>
v{currentVersion.label}{" "}
{currentVersion.label == versions[0].label ? " (current)" : ""}
{currentVersion ? `v${currentVersion.label}` : "Version"}{" "}
{currentVersion && currentVersion.label === versions[0].label
? " (current)"
: ""}
</span>
</button>
{isOpen && (
Expand Down
Loading