1
0
mirror of synced 2025-12-19 18:10:59 -05:00

[Take 2] Throw error if children entry can't be found, even if early access (#35523)

This commit is contained in:
Sarah Schneider
2023-03-14 09:57:24 -04:00
committed by GitHub
parent ee25e81142
commit f002576a3c
2 changed files with 16 additions and 10 deletions

View File

@@ -30,14 +30,19 @@ export default async function createTree(originalPath, rootPath, previousTree) {
try { try {
mtime = await getMtime(filepath) mtime = await getMtime(filepath)
} catch (error) { } catch (error) {
if (error.code === 'ENOENT' && filepath.split(path.sep).includes('early-access')) { if (error.code !== 'ENOENT') {
// Do not throw an error if Early Access is not available. throw error
console.warn( }
`${filepath} could not be turned into a Page, but is ignored because it's early-access` // Throw an error if we can't find a content file associated with the children: entry.
) // But don't throw an error if the user is running the site locally and hasn't cloned the Early Access repo.
if (originalPath === path.join('content', 'early-access')) {
return return
} }
throw error throw new Error(
`Cannot find a content file at ${originalPath}. Fix the children frontmatter entry "/${path.basename(
originalPath
)}" in ${path.dirname(originalPath)}/index.md.\n`
)
} }
} }
@@ -114,9 +119,6 @@ export default async function createTree(originalPath, rootPath, previousTree) {
// (early exit instead of returning a tree). So let's // (early exit instead of returning a tree). So let's
// mutate the `page.children` so we can benefit from the // mutate the `page.children` so we can benefit from the
// ability to reload the site tree on consective requests. // ability to reload the site tree on consective requests.
if (child !== 'early-access') {
console.warn(`Remove '${child}' from ${item.page.children}`)
}
item.page.children = item.page.children.filter((c) => c !== child) item.page.children = item.page.children.filter((c) => c !== child)
} }
return subTree return subTree

View File

@@ -1,3 +1,7 @@
import { main } from './start-server.js' import { main } from './start-server.js'
main() try {
await main()
} catch (error) {
console.error(error)
}