11import type { NavItemWithLink , NormalizedSidebar } from '../types/defaultTheme' ;
2- import { withBase , withoutBase } from './utils' ;
3- import { addTrailingSlash } from './utils' ;
42
53/**
64 * match the sidebar key in user config
@@ -10,22 +8,20 @@ import { addTrailingSlash } from './utils';
108export const matchSidebar = (
119 pattern : string ,
1210 currentPathname : string ,
13- base : string ,
1411) : boolean => {
15- const prefix = withBase ( pattern , base ) ;
16- if ( prefix === currentPathname ) {
12+ if ( pattern === currentPathname ) {
1713 return true ;
1814 }
19- const prefixWithTrailingSlash = addTrailingSlash ( prefix ) ;
20- if ( currentPathname . startsWith ( prefixWithTrailingSlash ) ) {
15+
16+ if ( currentPathname . startsWith ( pattern ) ) {
2117 return true ;
2218 }
2319
2420 // be compatible with api-extractor
2521 // '/api/react': [
2622 // { link: '/api/react.use' }
2723 // ]
28- const prefixWithDot = `${ prefix } .` ;
24+ const prefixWithDot = `${ pattern } .` ;
2925 return currentPathname . startsWith ( prefixWithDot ) ;
3026} ;
3127
@@ -38,7 +34,6 @@ export const matchSidebar = (
3834export const getSidebarDataGroup = (
3935 sidebar : NormalizedSidebar ,
4036 currentPathname : string ,
41- base : string ,
4237) : NormalizedSidebar [ string ] => {
4338 /**
4439 * why sort?
@@ -54,7 +49,7 @@ export const getSidebarDataGroup = (
5449 */
5550 const navRoutes = Object . keys ( sidebar ) . sort ( ( a , b ) => b . length - a . length ) ;
5651 for ( const name of navRoutes ) {
57- if ( matchSidebar ( name , currentPathname , base ) ) {
52+ if ( matchSidebar ( name , currentPathname ) ) {
5853 const sidebarGroup = sidebar [ name ] ;
5954 return sidebarGroup ;
6055 }
@@ -65,9 +60,6 @@ export const getSidebarDataGroup = (
6560export const matchNavbar = (
6661 item : NavItemWithLink ,
6762 currentPathname : string ,
68- base : string ,
6963) : boolean => {
70- return new RegExp ( item . activeMatch || item . link ) . test (
71- withoutBase ( currentPathname , base ) ,
72- ) ;
64+ return new RegExp ( item . activeMatch || item . link ) . test ( currentPathname ) ;
7365} ;
0 commit comments