From 2a6122b99d82951e9ae5dae5b170406cda763948 Mon Sep 17 00:00:00 2001 From: Lajos Szoke <63732287+laliconfigcat@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:08:20 +0100 Subject: [PATCH] API docs V2 only, no version dropdown (#506) --- .../DocsVersionDropdownNavbarItem.tsx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx diff --git a/website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx b/website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx new file mode 100644 index 000000000..79bc2534f --- /dev/null +++ b/website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import DocsVersionDropdownNavbarItem from '@theme-original/NavbarItem/DocsVersionDropdownNavbarItem'; +import type DocsVersionDropdownNavbarItemType from '@theme/NavbarItem/DocsVersionDropdownNavbarItem'; +import type { WrapperProps } from '@docusaurus/types'; +import { useLocation } from '@docusaurus/router'; + +type Props = WrapperProps; + +export default function DocsVersionDropdownNavbarItemWrapper(props: Props): JSX.Element { + const location = useLocation(); + + const unversionedRoutes = [ + // any route that starts with `/docs/api` + /^\/docs\/api\/.*$/g, + // If we want to disable it on the sdk reference too + // /^\/docs\/sdk-reference\/.*$/g + ] + + function checkPathname(pathname) { + // Check if the provided pathname matches any of the regexes in the list + return unversionedRoutes.some(regex => regex.test(pathname)) + } + + if (checkPathname(location.pathname)) { + return null; + } + + return ; +}