diff --git a/docusaurus.config.js b/docusaurus.config.js index d4fffb71..351a90f6 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -197,13 +197,12 @@ const config = { path: "runner-docs", routeBasePath: "runner", //sidebarPath: './runner/sidebars.js', + // the "current" runner docs are only a stub that re-uses the main + // docs runner page and do not describe the development version + // correctly, so they are not published + includeCurrentVersion: false, versions: { - current: { - label: "main", - banner: "unreleased", - }, "1.0.8": { - path: "1.0.8", label: "1.0.8", }, "0.2.11": { @@ -211,6 +210,8 @@ const config = { label: "0.2.11", }, }, + // no "path" for lastVersion, so the latest stable runner docs are + // served at /runner/ and links do not need updating on each release lastVersion: "1.0.8", editUrl: ({ versionDocsDirPath, @@ -397,16 +398,16 @@ const config = { label: "Docs", }, { - to: "/api/1.27/", + to: "/api/", label: "API", position: "left", - activeBaseRegex: "api/(1.22|1.23|1.24|1.25|1.26|1.27|next)/", + activeBaseRegex: "/api/", }, { - to: "/runner/1.0.8/", + to: "/runner/", label: "Runner", position: "left", - activeBaseRegex: "runner/(1.0.8|0.2.11|next)/", + activeBaseRegex: "/runner/", }, { position: "left", @@ -434,7 +435,7 @@ const config = { position: "right", items: [ { to: "/api/next/", label: "1.28-dev" }, - { to: "/api/1.27/", label: "1.27.1" }, + { to: "/api/", label: "1.27.1" }, { to: "/api/1.26/", label: "1.26.4" }, { to: "/api/1.25/", label: "1.25.5" }, { to: "/api/1.24/", label: "1.24.7" }, @@ -449,8 +450,7 @@ const config = { label: "Runner Version", position: "right", items: [ - { to: "/runner/next/", label: "development" }, - { to: "/runner/1.0.8/", label: "1.0.8" }, + { to: "/runner/", label: "1.0.8" }, { to: "/runner/0.2.11/", label: "0.2.11" }, ], routerRgx: "/runner/", diff --git a/src/components/DropDown.js b/src/components/DropDown.js index cd768976..aea97fd5 100644 --- a/src/components/DropDown.js +++ b/src/components/DropDown.js @@ -1,15 +1,39 @@ import React from 'react'; import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem'; import {useLocation} from '@docusaurus/router'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; + +// ensure a single trailing slash so paths can be compared as prefixes +function withTrailingSlash(path) { + return path.endsWith('/') ? path : `${path}/`; +} + +// baseUrl contains the locale prefix on localized builds (e.g. "/zh-cn/"), +// while the configured item paths never do +function stripBaseUrl(pathname, baseUrl) { + return pathname.startsWith(baseUrl) + ? `/${pathname.slice(baseUrl.length)}` + : pathname; +} export default function DropDown(props) { const {pathname} = useLocation(); + const {siteConfig} = useDocusaurusContext(); const {routerRgx, classNames} = props; const r = new RegExp(routerRgx); let isMatched = r.test(pathname); let newLabel = props.label; if (isMatched) { - newLabel = props.items.filter(item => item.to === pathname)[0]?.label ?? newLabel; + const currentPath = withTrailingSlash( + stripBaseUrl(pathname, siteConfig.baseUrl) + ); + // the latest version is served without a version segment (e.g. "/api/"), + // so match the longest item path that prefixes the current location + // instead of requiring an exact match + const bestMatch = props.items + .filter(item => currentPath.startsWith(withTrailingSlash(item.to))) + .sort((a, b) => b.to.length - a.to.length)[0]; + newLabel = bestMatch?.label ?? newLabel; } const newProps = {...props, label: newLabel}; return (