MDX is a flavor of Markdown that supports JavaScript expressions right in the Markdown file.
Astro also supports MDX via a first-party integration. MDX is a subset of markdown that allows you to use JSX in your markdown content.
That sounds kinda gross, to be honest. But let’s look at how we can set that up in Astro.
First, we need to add the MDX integration via astro add
.
npx astro add mdx
Astro will update the astro.config.mjs
file for you automatically, importing the MDX integration and adding it to the array integrations available to Astro.
Now let’s create a new file called code-of-conduct.mdx
and add some basic information to it:
---
layout: ../layouts/MarkdownArticleLayout.astro
title: Code of Conduct
---
import MarketNews from '../components/MarketNews.astro'
# {frontmatter.title}
Text here...
<MarketNews />
More text here...
Now we can drop an Astro component right inside of the content. This is fine for content authored by a developer but is hardly appropriate for a truly nice content authoring experience.
Astro Quick-Start Guide is made up of the following videos: