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

fix($theme-default): front matter prev / next links #1140

Closed
wants to merge 1 commit into from
Closed
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
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just some thoughts i had while looking at this: Compute the map only once and update in dev mode when the site data changes. Some check like here and then recompute the map might work.

module.hot.accept(VUEPRESS_TEMP_PATH + '/internal/siteData.js', () => {

Copy link
Author

Choose a reason for hiding this comment

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

seems a very good idea, but webpack hot module replacement is way outside my skill set. I guess I should add learning it to my 2019 new year's resolutions! Also, where do I save the page map, the site object seems like it's not currently passed in.

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