jlengstorf / gatsby-intermediate

https://frontendmasters.com/courses/intermediate-gatsby/
MIT License
54 stars 48 forks source link

Creating MDX Page shows error #20

Open mbcod3 opened 3 years ago

mbcod3 commented 3 years ago

After setting up templates to create mdx page, I get 404 error onhomepage. I have cloned the repo as well and switched to create pages from nodes commit and I still get the same error.

Homepage state https://imgur.com/W59kGUm

It shows it has created a page but the url is invalid i.e. '/\' https://imgur.com/VGc9rOg

In graphql playground if I query for docs page the path is shown as \ not \ https://imgur.com/6Gyd6oC

Repo is giving that error. I have no idea how to move forward?

jlengstorf commented 3 years ago

hey @mbcod3 — I'm not surprised that the \ as a slug is throwing an error, but I'm not sure where it could have come from

the home page slug should be a forward slash (/), not a backslash (\)

let me know if that doesn't work for you. thanks!

mbcod3 commented 3 years ago

Thank you for response. Unfortuantely there is no backslash in my code. Its not just my code. I cloned the repo for final project and simply ran it after installing dependencies it is showing the same error.

This is what gatsby-node has for onCreateNode

exports.onCreateNode = ({ node, actions, getNode, createNodeId }, options) => { const { basePath } = withDefaults(options); const parent = getNode(node.parent);

// Only work on MDX files that were loaded by this theme if ( node.internal.type !== 'Mdx' || parent.sourceInstanceName !== 'gatsby-theme-docs' ) { return; }

// Treat index.mdx link index.html (i.e. docs/ vs. docs/index/). const pageName = parent.name !== 'index' ? parent.name : '';

actions.createNode({ id: createNodeId(DocsPage-${node.id}), title: node.frontmatter.title || parent.name, updated: parent.modifiedTime, path: path.join('/', basePath, parent.relativeDirectory, pageName), parent: node.id, internal: { type: 'DocsPage', contentDigest: node.internal.contentDigest, }, });