Unverified Commit 65fcf351 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Add new getFileForPage helper to build utils (#6999)

parent a44788fb
...@@ -45,6 +45,24 @@ function getPossibleFiles(pageExtensions: string[], pages: string[]) { ...@@ -45,6 +45,24 @@ function getPossibleFiles(pageExtensions: string[], pages: string[]) {
return flatten<string>(res) return flatten<string>(res)
} }
export async function getFileForPage({
page,
pagesDirectory,
pageExtensions,
}: {
page: string
pagesDirectory: string
pageExtensions: string[]
}) {
const theFile = getPossibleFiles(pageExtensions, [
path.join(pagesDirectory, page),
]).find(f => fs.existsSync(f) && fs.lstatSync(f).isFile())
if (theFile) {
return path.sep + path.relative(pagesDirectory, theFile)
}
return theFile
}
export async function getSpecifiedPages( export async function getSpecifiedPages(
dir: string, dir: string,
pagesString: string, pagesString: string,
......
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