WhoBuilt

Building A Blog With MDX

Jul 3, 2020· 33 min· 31K views·Watch on YouTube

An unnamed instructor from Learn Next.js demonstrates how to build an MDX blog with Next.js, including custom React components and a newsletter signup.

MDX and CMS tradeoffs

MDX combines Markdown with React components, so developers can add custom elements such as graphs, diagrams, or forms to posts. The instructor contrasts this with WordPress and headless CMSs such as Contentful and Sanity, noting that CMSs can offer a GUI for non-developer contributors and handle image optimization.

Set up an MDX blog

The instructor shows a finished blog and then configures a simple Next.js app to load `.mdx` files. File based routing turns post files into routes, while a local data list supplies titles, dates, and slugs for a blog index.

Add a styled newsletter form

A React form is added to an MDX page using Theme UI components, including fields for email and first name. The instructor connects it to StaticKit, uses its React form hook to submit signups, and resolves a 404 caused by using instructions for a different library version.

Customize how posts render

The instructor revisits the completed blog and shows how an MDX provider maps Markdown elements to custom React components. The same page component can wrap posts, set content width, add Open Graph metadata, and include elements such as a course promotion.

Takeaways

  • Choose MDX when developers manage content and benefit from keeping posts alongside application code.
  • Consider a CMS when non-developers need an editing interface or managed image processing.
  • Use Next.js file based routing to turn MDX files into post pages.
  • Map Markdown elements to React components to control post styling and add reusable features.
  • Check the installed library version when integration instructions produce errors.

Mentioned in this talk

Search inside this talk

What was claimed 9

  • feature
    Markdown: Supports integrating components inside Markdown
    “MDX allows you to integrate components inside your Markdown.”
    YouTube
    Unverified1 source· Talk
  • integrates with
    React integrates with Markdown
    “it really pairs well with something like React”
    YouTube
    Unverified1 source· Talk
  • feature
    Sanity: Headless CMS with APIs and interfaces for managing content
    “I’ve worked with them a little in the past and enjoyed the experience as a developer, managing content and working with their APIs and interfaces.”
    YouTube
    Unverified1 source· Talk
  • feature
    Contentful: Headless CMS with APIs and interfaces for managing content
    “I’ve worked with them a little in the past and enjoyed the experience as a developer, managing content and working with their APIs and interfaces.”
    YouTube
    Unverified1 source· Talk
  • uses
    “To configure our application to understand MDX, we need to override the Next.js config and use that plugin.”
    YouTube
    Unverified1 source· Talk
  • feature
    Next.js: Provides file-based routing for pages
    “these files are automatically turned into those routes”
    YouTube
    Unverified1 source· Talk
  • feature
    StaticKit: Captures website form submissions and manages leads without requiring the user to set up backend code
    “Why write backend code if you don't have to?”
    YouTube
    Unverified1 source· Talk
  • uses
    “Another similar component library based on Styled System is called Theme UI.”
    YouTube
    Unverified1 source· Talk
Show all 9 facts

Related talks