From 3db031378f55f4b709e01bbf4bcd100322160e38 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Sat, 27 Nov 2021 23:38:28 -0800 Subject: [PATCH] chore: Add error when path does not match slug --- gatsby-node.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gatsby-node.js b/gatsby-node.js index 0273d6217..815cf7cf4 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -96,6 +96,23 @@ exports.createPages = async ({ actions, graphql, reporter }) => { }); } + if (frontmatter.path !== slug) { + const newPath = path.join( + 'src/markdown-pages', + fileRelativePath.endsWith('index.mdx') + ? path.join(frontmatter.path, 'index.mdx') + : `${frontmatter.path}.mdx` + ); + + reporter.error( + ` +File path does not match frontmatter path: + mkdir -p ${path.dirname(newPath)} + mv ${fileRelativePath} ${newPath} +`.trim() + ); + } + createPage({ path: frontmatter.path ? path.join(frontmatter.path, '/')