Skip to content
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

perf: improve ssr performance #1068

Merged
merged 5 commits into from
Dec 17, 2018
Merged
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
18 changes: 10 additions & 8 deletions packages/@vuepress/theme-default/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

@sullivanpt sullivanpt Dec 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the function signature but doesn't update all the callers. resolvePage is also called from the default theme. See vuepress/packages/@vuepress/theme-default/components/Page.vue computed.prev. which is now broken and gives an error when trying to use frontmatter prev / next links. See #1140 for a primitive fix. Thanks.

return Object.assign({}, pages[path], {
type: 'page',
path: ensureExt(pages[path].path)
})
}
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
return {}
Expand Down Expand Up @@ -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))
: []
}
}
Expand Down