Skip to content

Commit

Permalink
fix($theme-default): front matter prev / next links
Browse files Browse the repository at this point in the history
fixes bug introduced with vuejs#1068.
  • Loading branch information
sullivanpt committed Dec 29, 2018
1 parent fd09bad commit 226fdd7
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/@vuepress/theme-default/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ export function isActive (route, path) {
return routePath === pagePath
}

function normalizedPagesMap (pages) {
return pages.reduce((map, page) => {
map[normalize(page.regularPath)] = page
return map
}, {})
}

export function resolvePage (pages, rawPath, base) {
return resolvePageByMap(normalizedPagesMap(pages), rawPath, base)
}

function resolvePageByMap (pages, rawPath, base) {
if (base) {
rawPath = resolvePath(rawPath, base)
}
Expand Down Expand Up @@ -126,16 +137,12 @@ 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, normalizedPagesMap, base))
? config.map(item => resolveItem(item, normalizedPagesMap(pages), base))
: []
}
}
Expand Down Expand Up @@ -211,9 +218,9 @@ function ensureEndingSlash (path) {

function resolveItem (item, pages, base, isNested) {
if (typeof item === 'string') {
return resolvePage(pages, item, base)
return resolvePageByMap(pages, item, base)
} else if (Array.isArray(item)) {
return Object.assign(resolvePage(pages, item[0], base), {
return Object.assign(resolvePageByMap(pages, item[0], base), {
title: item[1]
})
} else {
Expand Down

0 comments on commit 226fdd7

Please sign in to comment.