Prose UI with Next.js and Content Collections
Create a new project
Start by creating a new Next.js app and selecting the recommended Next.js defaults when prompted.
Set up MDX rendering with Content Collections
Content Collections helps you organize your MDX content and render MDX files. The setup below follows the official Next.js quickstart and MDX guides.
You can also set up Prose UI with next/mdx. In this guide we use Content Collections because it keeps all Markdown files in a single place and provides a great developer experience.
Install the required packages:
Add the content-collections path to your tsconfig.json:
Update your Next.js configuration:
Add .content-collections to your .gitignore:
Create a content-collections.ts file in the root of your project:
Set up Prose UI and Markdown rendering
Install Prose UI dependencies:
Import the styles into your globals.css:
In content-collections.ts, initialize and pass remarkPlugins to the MDX compiler:
Create the page that will render your Markdown at /app/posts/[[...path]]/page.tsx. Pass Prose UI mdxComponents to MDXContent, and wrap the content in an element with the prose-ui CSS class.
Add your first page
Create a content/posts folder (if it doesn't exist yet) and add a page:
Run your project and open http://localhost:3000/posts/hello to view the rendered MDX page.