GATSBY MDX BLOG
Project Setup
- Base - Gatsby Starter
- Components + Imports - ready
- main.css + styled components
- constants (different setup)
- Complete React Components for MDX
Boring Components
- Navbar
- Sidebar
- Hero
- Footer
- Error Page
- Newsletter
<form
className="contact-form"
name="contact"
method="post"
netlify-honeypot="bot-field"
data-netlify="true"
action="/success"
>
<input type="hidden" name="bot-field" />
<input type="hidden" name="form-name" value="contact" />
</form>
Basic MDX Setup
- Install mdx plugin
- Add
gatsby-plugin-mdx
to gatsby-config - Setup Page - pageName.mdx /pages
- Basic Markdown
- Add React Components including Gatsby Link
- Basic Styling
- New Line Gotcha
Multiple Posts
- Setup Posts Folder
- Add New filesystem Instance to gatsby-config
{
resolve: `gatsby-source-filesystem`,
options: {
name: `posts`,
path: `${__dirname}/src/posts`,
},
},
- Create a Brand New Folder For Post Won't Query Name - setup is up to you
- Add mdx file
- DOUBLE CHECK PATHS (../../ - gotcha)
- Run 'gatsby clean' - just to be on the safe side
- Seperate Images Folder
- FrontMatter (space gotcha - title: first post)
- Imports after FrontMatter
Create MDX Pages Programatically
- Setup Query with unique value (most likely slug)
- Setup Template
- Run Query in gatsby-node.js - just like normal setup
- Pass Variable (slug)
- Run Query in Template using variable (slug)
Add INLINE Images to MDX
-
Syntax - ![](./pathToImages/imageName - if in the same folder)
-
Install - gatsby-transformer-remark
-
Changes in gatsby config
remove - 'gatsby-plugin-mdx' add
{
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [{ resolve: "gatsby-remark-images" }],
},
},
- Restart the server
- Whitespace gotchas and "gatsby clean"
- Styling - Good Luck!
Videos
Reg Video
- The same as regular video
- autoPlay - gotcha
- use like regular component
Iframe
- Gatsby Docs
- Gotchas - url, styling
- Use in template - johnsmilga.com
MDX
[MDX Reference] : https://mdxjs.com/getting-started
[ Elements Reference] : https://www.gatsbyjs.org/docs/mdx/customizing-components/