Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 05417d3

Browse files
committed
fix(docz-core): use user-provided 404 page when it exists
Looks in ${themesDir}/pages/ which defaults to src/pages/
1 parent 34ba273 commit 05417d3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

core/docz-core/src/bundler/machine/actions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const ensureFile = (filename: string, toDelete?: string) => {
1919
}
2020

2121
export const ensureFiles = ({ args }: ServerMachineCtx) => {
22+
// themesDir defaults to "src" to behave like a normal gatsby site
2223
const appPath = path.join(paths.root, args.themesDir)
2324
const themeNames = glob.sync('gatsby-theme-**', {
2425
cwd: appPath,
@@ -30,6 +31,13 @@ export const ensureFiles = ({ args }: ServerMachineCtx) => {
3031
path.join(paths.docz, 'src', themeName)
3132
)
3233
})
34+
const userPagesPath = path.join(appPath, 'pages')
35+
const doczPagesPath = path.join(paths.docz, 'src', 'pages')
36+
// Copy 404 and other possible Gatsby pages
37+
if (fs.existsSync(userPagesPath)) {
38+
fs.copySync(userPagesPath, doczPagesPath)
39+
}
40+
3341
copyDoczRc(args.config)
3442
ensureFile('gatsby-browser.js')
3543
ensureFile('gatsby-ssr.js')

core/docz-core/src/bundler/machine/services/create-resources.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ const copyEslintIgnore = async () => {
8080
}
8181
}
8282

83-
export const writeNotFound = async () => {
83+
export const writeDefaultNotFound = async () => {
8484
const outputPath = path.join(paths.docz, 'src/pages/404.js')
85+
// If it exists then it would have been created in ensureFiles while copying the theme
86+
if (fs.existsSync(outputPath)) return
8587
await outputFileFromTemplate('404.tpl.js', outputPath, {})
8688
}
8789

@@ -132,7 +134,7 @@ export const createResources = async (ctx: ServerMachineCtx) => {
132134
await copyAndModifyPkgJson(ctx)
133135
await writeEslintRc()
134136
await copyEslintIgnore()
135-
await writeNotFound()
137+
await writeDefaultNotFound()
136138
await writeGatsbyConfig(ctx)
137139
await writeGatsbyConfigNode()
138140
await writeGatsbyConfigCustom()

0 commit comments

Comments
 (0)