diff --git a/packages/@vuepress/theme-default/util/index.js b/packages/@vuepress/theme-default/util/index.js index 01937e9888..192a9a4bcf 100644 --- a/packages/@vuepress/theme-default/util/index.js +++ b/packages/@vuepress/theme-default/util/index.js @@ -58,13 +58,11 @@ export function resolvePage (pages, rawPath, base) { rawPath = resolvePath(rawPath, base) } const path = normalize(rawPath) - for (let i = 0; i < pages.length; i++) { - if (normalize(pages[i].regularPath) === path) { - return Object.assign({}, pages[i], { - type: 'page', - path: ensureExt(pages[i].path) - }) - } + if (path in pages) { + return Object.assign({}, pages[path], { + type: 'page', + path: ensureExt(pages[path].path) + }) } console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`) return {} @@ -128,12 +126,16 @@ export function resolveSidebarItems (page, regularPath, site, localePath) { } const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar + const normalizedPagesMap = pages.reduce((map, page) => { + map[normalize(page.regularPath)] = page + return map + }, {}) if (!sidebarConfig) { return [] } else { const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig) return config - ? config.map(item => resolveItem(item, pages, base)) + ? config.map(item => resolveItem(item, normalizedPagesMap, base)) : [] } }