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: Cannot get correct $page when a trailing slash is missed. (close: #183) #185

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion lib/app/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function ensureEndingSlash (path) {
return /(\.html|\/)$/.test(path)
? path
: path + '/'
}

export function pathToComponentName (path) {
if (path.charAt(path.length - 1) === '/') {
return `page${path.replace(/\//g, '-') + 'index'}`
Expand All @@ -9,7 +15,7 @@ export function pathToComponentName (path) {
export function findPageForPath (pages, path) {
for (let i = 0; i < pages.length; i++) {
const page = pages[i]
if (page.path === path) {
if (page.path === ensureEndingSlash(path)) {
return page
}
}
Expand Down
8 changes: 2 additions & 6 deletions lib/default-theme/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ensureEndingSlash } from '../app/util'

export const hashRE = /#.*$/
export const extRE = /\.(md|html)$/
export const endingSlashRE = /\/$/
Expand Down Expand Up @@ -184,12 +186,6 @@ export function resolveMatchingConfig (route, config) {
return {}
}

function ensureEndingSlash (path) {
return /(\.html|\/)$/.test(path)
? path
: path + '/'
}

function resolveItem (item, pages, base, isNested) {
if (typeof item === 'string') {
return resolvePage(pages, item, base)
Expand Down