mirror of
https://gitea.com/gitea/docs.git
synced 2026-09-20 04:58:52 +00:00
Fix navbar links and hide runner's development (#477)
Reviewed-on: https://gitea.com/gitea/docs/pulls/477
This commit is contained in:
+12
-12
@@ -197,13 +197,12 @@ const config = {
|
|||||||
path: "runner-docs",
|
path: "runner-docs",
|
||||||
routeBasePath: "runner",
|
routeBasePath: "runner",
|
||||||
//sidebarPath: './runner/sidebars.js',
|
//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: {
|
versions: {
|
||||||
current: {
|
|
||||||
label: "main",
|
|
||||||
banner: "unreleased",
|
|
||||||
},
|
|
||||||
"1.0.8": {
|
"1.0.8": {
|
||||||
path: "1.0.8",
|
|
||||||
label: "1.0.8",
|
label: "1.0.8",
|
||||||
},
|
},
|
||||||
"0.2.11": {
|
"0.2.11": {
|
||||||
@@ -211,6 +210,8 @@ const config = {
|
|||||||
label: "0.2.11",
|
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",
|
lastVersion: "1.0.8",
|
||||||
editUrl: ({
|
editUrl: ({
|
||||||
versionDocsDirPath,
|
versionDocsDirPath,
|
||||||
@@ -397,16 +398,16 @@ const config = {
|
|||||||
label: "Docs",
|
label: "Docs",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
to: "/api/1.27/",
|
to: "/api/",
|
||||||
label: "API",
|
label: "API",
|
||||||
position: "left",
|
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",
|
label: "Runner",
|
||||||
position: "left",
|
position: "left",
|
||||||
activeBaseRegex: "runner/(1.0.8|0.2.11|next)/",
|
activeBaseRegex: "/runner/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
position: "left",
|
position: "left",
|
||||||
@@ -434,7 +435,7 @@ const config = {
|
|||||||
position: "right",
|
position: "right",
|
||||||
items: [
|
items: [
|
||||||
{ to: "/api/next/", label: "1.28-dev" },
|
{ 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.26/", label: "1.26.4" },
|
||||||
{ to: "/api/1.25/", label: "1.25.5" },
|
{ to: "/api/1.25/", label: "1.25.5" },
|
||||||
{ to: "/api/1.24/", label: "1.24.7" },
|
{ to: "/api/1.24/", label: "1.24.7" },
|
||||||
@@ -449,8 +450,7 @@ const config = {
|
|||||||
label: "Runner Version",
|
label: "Runner Version",
|
||||||
position: "right",
|
position: "right",
|
||||||
items: [
|
items: [
|
||||||
{ to: "/runner/next/", label: "development" },
|
{ to: "/runner/", label: "1.0.8" },
|
||||||
{ to: "/runner/1.0.8/", label: "1.0.8" },
|
|
||||||
{ to: "/runner/0.2.11/", label: "0.2.11" },
|
{ to: "/runner/0.2.11/", label: "0.2.11" },
|
||||||
],
|
],
|
||||||
routerRgx: "/runner/",
|
routerRgx: "/runner/",
|
||||||
|
|||||||
@@ -1,15 +1,39 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
||||||
import {useLocation} from '@docusaurus/router';
|
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) {
|
export default function DropDown(props) {
|
||||||
const {pathname} = useLocation();
|
const {pathname} = useLocation();
|
||||||
|
const {siteConfig} = useDocusaurusContext();
|
||||||
const {routerRgx, classNames} = props;
|
const {routerRgx, classNames} = props;
|
||||||
const r = new RegExp(routerRgx);
|
const r = new RegExp(routerRgx);
|
||||||
let isMatched = r.test(pathname);
|
let isMatched = r.test(pathname);
|
||||||
let newLabel = props.label;
|
let newLabel = props.label;
|
||||||
if (isMatched) {
|
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};
|
const newProps = {...props, label: newLabel};
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user