Skip to content

Commit 226fdd7

Browse files
committed
fix($theme-default): front matter prev / next links
fixes bug introduced with vuejs#1068.
1 parent fd09bad commit 226fdd7

File tree

1 file changed

+14
-7
lines changed
  • packages/@vuepress/theme-default/util

1 file changed

+14
-7
lines changed

packages/@vuepress/theme-default/util/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,18 @@ export function isActive (route, path) {
5353
return routePath === pagePath
5454
}
5555

56+
function normalizedPagesMap (pages) {
57+
return pages.reduce((map, page) => {
58+
map[normalize(page.regularPath)] = page
59+
return map
60+
}, {})
61+
}
62+
5663
export function resolvePage (pages, rawPath, base) {
64+
return resolvePageByMap(normalizedPagesMap(pages), rawPath, base)
65+
}
66+
67+
function resolvePageByMap (pages, rawPath, base) {
5768
if (base) {
5869
rawPath = resolvePath(rawPath, base)
5970
}
@@ -126,16 +137,12 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
126137
}
127138

128139
const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
129-
const normalizedPagesMap = pages.reduce((map, page) => {
130-
map[normalize(page.regularPath)] = page
131-
return map
132-
}, {})
133140
if (!sidebarConfig) {
134141
return []
135142
} else {
136143
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
137144
return config
138-
? config.map(item => resolveItem(item, normalizedPagesMap, base))
145+
? config.map(item => resolveItem(item, normalizedPagesMap(pages), base))
139146
: []
140147
}
141148
}
@@ -211,9 +218,9 @@ function ensureEndingSlash (path) {
211218

212219
function resolveItem (item, pages, base, isNested) {
213220
if (typeof item === 'string') {
214-
return resolvePage(pages, item, base)
221+
return resolvePageByMap(pages, item, base)
215222
} else if (Array.isArray(item)) {
216-
return Object.assign(resolvePage(pages, item[0], base), {
223+
return Object.assign(resolvePageByMap(pages, item[0], base), {
217224
title: item[1]
218225
})
219226
} else {

0 commit comments

Comments
 (0)