Skip to content

Commit

Permalink
fix(docz-core): use user-provided 404 page when it exists
Browse files Browse the repository at this point in the history
Looks in ${themesDir}/pages/
which defaults to src/pages/
  • Loading branch information
rakannimer committed Apr 7, 2020
1 parent 34ba273 commit 05417d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/docz-core/src/bundler/machine/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ensureFile = (filename: string, toDelete?: string) => {
}

export const ensureFiles = ({ args }: ServerMachineCtx) => {
// themesDir defaults to "src" to behave like a normal gatsby site
const appPath = path.join(paths.root, args.themesDir)
const themeNames = glob.sync('gatsby-theme-**', {
cwd: appPath,
Expand All @@ -30,6 +31,13 @@ export const ensureFiles = ({ args }: ServerMachineCtx) => {
path.join(paths.docz, 'src', themeName)
)
})
const userPagesPath = path.join(appPath, 'pages')
const doczPagesPath = path.join(paths.docz, 'src', 'pages')
// Copy 404 and other possible Gatsby pages
if (fs.existsSync(userPagesPath)) {
fs.copySync(userPagesPath, doczPagesPath)
}

copyDoczRc(args.config)
ensureFile('gatsby-browser.js')
ensureFile('gatsby-ssr.js')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ const copyEslintIgnore = async () => {
}
}

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

Expand Down Expand Up @@ -132,7 +134,7 @@ export const createResources = async (ctx: ServerMachineCtx) => {
await copyAndModifyPkgJson(ctx)
await writeEslintRc()
await copyEslintIgnore()
await writeNotFound()
await writeDefaultNotFound()
await writeGatsbyConfig(ctx)
await writeGatsbyConfigNode()
await writeGatsbyConfigCustom()
Expand Down

0 comments on commit 05417d3

Please sign in to comment.