fix(theme): fix incorrect auto-sidebar-link parse (#880)

This commit is contained in:
pengzhanbo 2026-04-02 16:37:58 +08:00 committed by GitHub
parent 7ce4e40521
commit 7febfbf237
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,32 +14,26 @@ export function resolveLinkBySidebar(
for (const item of sidebar) {
if (typeof item !== 'string') {
const { prefix, dir = '', link = '/', items, text = '' } = item
getSidebarLink(items, link, text, path.join(_prefix, prefix || dir), res)
const { prefix, dir = '', link = '/', items } = item
getSidebarLink(items, link, path.join(_prefix, prefix || dir), res)
}
}
return res
}
function getSidebarLink(items: 'auto' | (string | ThemeSidebarItem)[] | undefined, link: string, text: string, dir = '', res: Record<string, string> = {}) {
if (items === 'auto')
function getSidebarLink(items: 'auto' | (string | ThemeSidebarItem)[] | undefined, link: string, dir = '', res: Record<string, string> = {}) {
if (items === 'auto' || !items)
return
if (!items) {
res[ensureEndingSlash(dir)] = link
return
}
for (const item of items) {
if (typeof item === 'string') {
res[ensureEndingSlash(dir)] = link
}
else {
const { prefix = '', dir: subDir = '', link: subLink = '/', items: subItems, text: subText = '' } = item
const { prefix = '', dir: subDir = '', link: subLink = '/', items: subItems } = item
getSidebarLink(
subItems,
path.join(link, subLink),
subText,
path.join(prefix[0] === '/' ? prefix : `/${dir}/${prefix || subDir}`),
res,
)