File tree Expand file tree Collapse file tree 4 files changed +11
-19
lines changed
__tests__/client/theme-default/support
src/client/theme-default/support Expand file tree Collapse file tree 4 files changed +11
-19
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ describe('client/theme-default/support/sideBar', () => {
1616
1717 it ( 'gets the correct sidebar items from the given path' , ( ) => {
1818 const sidebar = {
19- '/' : [ { text : 'R ' , link : 'r ' } ] ,
20- '/guide/ ' : [ { text : 'G ' , link : 'g ' } ]
19+ '/guide/ ' : [ { text : 'G ' , link : 'g ' } ] ,
20+ '/' : [ { text : 'R ' , link : 'r ' } ]
2121 }
2222
2323 expect ( getSideBarConfig ( sidebar , '/' ) ) . toEqual ( sidebar [ '/' ] )
@@ -31,7 +31,8 @@ describe('client/theme-default/support/sideBar', () => {
3131 }
3232
3333 expect ( getSideBarConfig ( s , '/guide/' ) ) . toEqual ( s [ '/guide/' ] )
34- expect ( getSideBarConfig ( s , '/guide' ) ) . toEqual ( s [ '/guide/' ] )
34+ // no ending slash should not match
35+ expect ( getSideBarConfig ( s , '/guide' ) ) . not . toEqual ( s [ '/guide/' ] )
3536 expect ( getSideBarConfig ( s , 'guide/' ) ) . toEqual ( s [ '/guide/' ] )
3637 expect ( getSideBarConfig ( s , 'guide/nested' ) ) . toEqual ( s [ '/guide/' ] )
3738 expect ( getSideBarConfig ( s , '/guide/nested' ) ) . toEqual ( s [ '/guide/' ] )
Original file line number Diff line number Diff line change @@ -32,9 +32,9 @@ module.exports = {
3232 ] ,
3333
3434 sidebar : {
35- '/' : getGuideSidebar ( ) ,
3635 '/guide/' : getGuideSidebar ( ) ,
37- '/config/' : getConfigSidebar ( )
36+ '/config/' : getConfigSidebar ( ) ,
37+ '/' : getGuideSidebar ( )
3838 }
3939 }
4040}
Original file line number Diff line number Diff line change 11import { DefaultTheme } from '../config'
2- import {
3- isArray ,
4- ensureSlash ,
5- ensureStartingSlash ,
6- removeExtention
7- } from '../utils'
2+ import { isArray , ensureStartingSlash , removeExtention } from '../utils'
83
94export function isSideBarConfig (
105 sidebar : DefaultTheme . SideBarConfig | DefaultTheme . MultiSideBarConfig
@@ -32,15 +27,11 @@ export function getSideBarConfig(
3227 return sidebar
3328 }
3429
35- // get the very first segment of the path to compare with multiple sidebar keys
36- // and make sure it's surrounded by slash
37- path = removeExtention ( path )
38- path = ensureStartingSlash ( path ) . split ( '/' ) [ 1 ] || '/'
39- path = ensureSlash ( path )
30+ path = ensureStartingSlash ( path )
4031
4132 for ( const dir in sidebar ) {
42- // make sure the multi sidebar key is surrounded by slash too
43- if ( path === ensureSlash ( dir ) ) {
33+ // make sure the multi sidebar key starts with slash too
34+ if ( path . startsWith ( ensureStartingSlash ( dir ) ) ) {
4435 return sidebar [ dir ]
4536 }
4637 }
Original file line number Diff line number Diff line change 1717 "tests/*" : [" __tests__/*" ],
1818 "/@shared/*" : [" src/client/shared/*" ],
1919 "/@types/*" : [" types/*" ],
20- "vitepress" : [" src/client/app/exports .ts" ]
20+ "vitepress" : [" src/client/index .ts" ]
2121 }
2222 },
2323 "include" : [
You can’t perform that action at this time.
0 commit comments