Fix navbar links and hide runner's development (#477)

Reviewed-on: https://gitea.com/gitea/docs/pulls/477
This commit is contained in:
Lunny Xiao
2026-08-01 19:49:44 +00:00
parent a6b87cb424
commit 42a0f7f45f
2 changed files with 37 additions and 13 deletions
+25 -1
View File
@@ -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 (