Skip to content

Commit

Permalink
fix: Add deprecation warning for path property when creating pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Nov 28, 2021
1 parent 85c4d05 commit 9586bdf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,24 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
});
}

if (frontmatter.path !== slug) {
const newPath = path.join(
if (frontmatter.path) {
const recommendedPath = path.join(
'src/markdown-pages',
fileRelativePath.endsWith('index.mdx')
? path.join(frontmatter.path, 'index.mdx')
: `${frontmatter.path}.mdx`
);

reporter.error(
const recommendation =
recommendedPath === fileRelativePath
? "Please remove the 'path' property."
: `To render this page at '${frontmatter.path}', please move this file to: '${recommendedPath}'.`;

reporter.panicOnBuild(
`
File path does not match frontmatter path:
mkdir -p ${path.dirname(newPath)}
mv ${fileRelativePath} ${newPath}
${fileRelativePath}
The 'path' property on frontmatter is deprecated and has no effect. URLs are now generated using the path of the file. ${recommendation}
`.trim()
);
}
Expand Down

0 comments on commit 9586bdf

Please sign in to comment.