Skip to content

Commit 9d245a4

Browse files
committed
refactor(core): improve not-found page handling
1 parent 47edee1 commit 9d245a4

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

packages/core/src/app/resolveAppPages.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ export const resolveAppPages = async (app: App): Promise<Page[]> => {
1616
cwd: app.dir.source(),
1717
})
1818

19+
let hasNotFoundPage = false as boolean
20+
1921
// create pages from files
2022
const pages = await Promise.all(
21-
pageFilePaths.map(async (filePath) => createPage(app, { filePath })),
23+
pageFilePaths.map(async (filePath) => {
24+
const page = await createPage(app, { filePath })
25+
// if there is a 404 page, set the default layout to NotFound
26+
if (page.path === '/404.html') {
27+
page.frontmatter.layout ??= 'NotFound'
28+
hasNotFoundPage = true
29+
}
30+
return page
31+
}),
2232
)
2333

24-
// find the 404 page
25-
const notFoundPage = pages.find((page) => page.path === '/404.html')
26-
27-
// if there is a 404 page, set the default layout to NotFound
28-
if (notFoundPage) {
29-
notFoundPage.frontmatter.layout ??= 'NotFound'
30-
}
31-
// if there is no 404 page, add one
32-
else {
34+
// if there is no 404 page, add a virtual one
35+
if (!hasNotFoundPage) {
3336
pages.push(
3437
await createPage(app, {
3538
path: '/404.html',

pnpm-lock.yaml

Lines changed: 18 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)