Skip to content

Commit

Permalink
fix: make version dropdown work for optimize on preview sites
Browse files Browse the repository at this point in the history
  • Loading branch information
pepopowitz committed Feb 7, 2025
1 parent 8159feb commit 63007fb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/theme/NavbarItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type NavbarItemType from "@theme/NavbarItem";
import type { WrapperProps } from "@docusaurus/types";

import { useLocation } from "@docusaurus/router";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";

type Props = WrapperProps<typeof NavbarItemType> & {
docsPluginId: string;
Expand All @@ -20,9 +21,12 @@ export default function NavbarItemWrapper(props: Props): ReactNode {
// override docsPluginId for Optimize instance
const { type } = props;
const { pathname } = useLocation();
const {
siteConfig: { baseUrl },
} = useDocusaurusContext();

if (type === "docsVersionDropdown" || type === "docsVersion") {
if (/^\/([0-9.]*\/)?optimize/.test(pathname)) {
if (/^([0-9.]*\/)?optimize/.test(pathname.replace(baseUrl, ""))) {
childProps.docsPluginId = "optimize";
}
}
Expand Down

0 comments on commit 63007fb

Please sign in to comment.