Skip to content

Commit

Permalink
refactor(core): improve not-found page handling
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Sep 10, 2024
1 parent 47edee1 commit 9d245a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
23 changes: 13 additions & 10 deletions packages/core/src/app/resolveAppPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ export const resolveAppPages = async (app: App): Promise<Page[]> => {
cwd: app.dir.source(),
})

let hasNotFoundPage = false as boolean

// create pages from files
const pages = await Promise.all(
pageFilePaths.map(async (filePath) => createPage(app, { filePath })),
pageFilePaths.map(async (filePath) => {
const page = await createPage(app, { filePath })
// if there is a 404 page, set the default layout to NotFound
if (page.path === '/404.html') {
page.frontmatter.layout ??= 'NotFound'
hasNotFoundPage = true
}
return page
}),
)

// find the 404 page
const notFoundPage = pages.find((page) => page.path === '/404.html')

// if there is a 404 page, set the default layout to NotFound
if (notFoundPage) {
notFoundPage.frontmatter.layout ??= 'NotFound'
}
// if there is no 404 page, add one
else {
// if there is no 404 page, add a virtual one
if (!hasNotFoundPage) {
pages.push(
await createPage(app, {
path: '/404.html',
Expand Down
23 changes: 18 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d245a4

Please sign in to comment.