Commit a67b6ee1 authored by Joe Haddad's avatar Joe Haddad Committed by Tim Neutkens

Fix page resolution (#6920)

Previously this didn't work properly with nested pages.
parent d4048790
......@@ -46,9 +46,12 @@ function flatten<T>(arr: T[][]): T[] {
}
function getPossibleFiles(pageExtensions: string[], pages: string[]) {
const res = pages.map(page =>
[page].concat(pageExtensions.map(e => `${page}.${e}`))
)
const res = pages.map(page => {
const pi = path.join(page, 'index')
return [page, pi]
.concat(pageExtensions.map(e => `${page}.${e}`))
.concat(pageExtensions.map(e => `${pi}.${e}`))
})
return flatten<string>(res)
}
......@@ -81,12 +84,12 @@ export async function getSpecifiedPages(
resolvedPage = getPossibleFiles(pageExtensions, [
path.join(pagesDir, p),
p,
]).find(f => fs.existsSync(f))
]).find(f => fs.existsSync(f) && fs.lstatSync(f).isFile())
} else {
resolvedPage = getPossibleFiles(pageExtensions, [
path.join(pagesDir, p),
path.join(dir, p),
]).find(f => fs.existsSync(f))
]).find(f => fs.existsSync(f) && fs.lstatSync(f).isFile())
}
return { original: p, resolved: resolvedPage || null, removePage }
})
......
......@@ -12,7 +12,7 @@ Array [
"/_app.js",
"/_document.js",
"/b.jsx",
"/c.mdx",
"/c/index.mdx",
]
`;
......@@ -56,7 +56,7 @@ Array [
"/_document.js",
"/a.js",
"/b.jsx",
"/c.mdx",
"/c/index.mdx",
]
`;
......@@ -74,6 +74,6 @@ Array [
"/_document.js",
"/a.js",
"/b.jsx",
"/c.mdx",
"/c/index.mdx",
]
`;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment