Skip to content

fix(theme): fix getSidebar's buggy logic when supporting subtree-lift… #4842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/client/theme-default/support/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ export function getSidebar(

const dir = Object.keys(_sidebar)
.sort((a, b) => {
// longer dir link has higher priority
return b.split('/').length - a.split('/').length
})
.find((dir) => {
const dirWithStartingSlash = ensureStartingSlash(dir)
// make sure the multi sidebar key starts with slash too
return path.startsWith(ensureStartingSlash(dir))
if (path.startsWith(dirWithStartingSlash)) {
// "/" match everything and it has lowest priority
if (dirWithStartingSlash === '/') return true
const remains = path.replace(dirWithStartingSlash, '')
if (remains.startsWith('/') || remains === '') return true
}
})

const sidebar = dir ? _sidebar[dir] : []
Expand Down
Loading