While trying to follow the Gatsby tutorial, I ran into an issue with generating slugs for MDX files in a subdirectory of src/pages
. For instance, if I have a file like
src/pages/projects/devmarks/index.md
, the expected slug according to the tutorial should be devmarks
, allowing me to access the page at localhost:8000/projects/devmarks
. However, the actual slug ends up being projects/devmarks
, resulting in only being able to reach the fully rendered page at localhost:8000/projects/projects/devmarks
. Interestingly though, visiting localhost:8000/projects/devmarks
displays the content of the MDX file but without proper rendering. It seems like the createPages function in gatsby-node.js or moving the {mdx.slug}.tsx file up one level might resolve this issue, however, I’m puzzled as to why my code isn’t behaving as expected based on the tutorial.
gatsby-config.ts
import type { GatsbyConfig } from "gatsby";
const config: GatsbyConfig = {
siteMetadata: {
title: `Christopher Leggett's Portfolio and Blog`,
description: `The Portfolio and Blog for the aspiring software developer Christopher Leggett`,
siteUrl: `https://chrisleggett.me`,
twitterUsername: `@leggettc18`
},
plugins: ["gatsby-plugin-image", "gatsby-plugin-react-helmet", "gatsby-plugin-postcss", {
resolve: 'gatsby-plugin-manifest',
options: {
"icon": "src/images/icon.png"
}
}, "gatsby-plugin-mdx", "gatsby-plugin-sharp", "gatsby-transformer-sharp", {
resolve: 'gatsby-source-filesystem',
options: {
"name": "images",
"path": "./src/images/"
},
__key: "images"
}, {
resolve: 'gatsby-source-filesystem',
options: {
"name": "pages",
"path": "./src/pages/"
},
__key: "pages"
}]
};
export default config;
folder structure
- src
- images
- components
- layout.tsx
- css
- index.css //contains tailwind stuff
- pages
- index.tsx
- about.tsx
- 404.tsx
- projects
- {mdx.slug}.tsx
- devmarks
- index.mdx
In the tutorial, they had configured the source-filesystem plugin to point at a src/blog directory, which was not updated when they moved all the content to src/pages/blog. Having read through the tutorial beforehand, I organized my portfolio projects directly in src/pages/projects. Could this difference in organization be causing the discrepancy in how my slugs are generated compared to the tutorial?