Welcome to your comprehensive guide on writing beautiful, interactive blog posts using MDX! This guide will show you how to leverage our powerful component library to create engaging content.
What is MDX?
MDX is a powerful format that lets you write JSX in your markdown documents. It combines the simplicity of markdown with the power of React components.
Getting Started
Before you start writing your blog post, you'll need to understand the basic structure of an MDX file:
Create your MDX file
Create a new .mdx file in the src/content directory with a descriptive name.
Add frontmatter
Every blog post starts with frontmatter - metadata about your post:
---
title: "Your Blog Title"
brief: "A short description"
publishedAt: "2024-03-20T12:00:00Z"
readTimeInMinutes: 15
tags:
- name: "Tag Name"
slug: "tag-slug"
coverImage:
url: "your-image-url"
author:
name: "Your Name"
profilePicture: "your-profile-picture"
---Start writing
After the frontmatter, you can start writing your content using markdown and our custom components.
Component Library & Use Cases
Here are all the available components and how to use them effectively.
1. Callouts
Use Case: Highlighting warnings, tips, errors, or success messages that need to stand out from the main text.
Info
Use this for general information or context.
Warning
Use this to warn readers about potential pitfalls.
Error
Use this to highlight critical errors or anti-patterns.
Success
Use this to celebrate a completed step or correct approach.
<Callout type="info" title="Info">
Use this for general information or context.
</Callout>2. Code Blocks
Use Case: Displaying code snippets with syntax highlighting, file names, and copy functionality.
interface User {
id: string;
name: string;
email: string;
}
const getUser = (id: string): User => {
// Fetch user logic
return { id, name: "John Doe", email: "john@example.com" };
};3. Interactive Demos
Use Case: Showcasing interactive widgets or UI elements directly in the blog post.
<Demo title="Button Component">
<button className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors shadow-lg">
Click Me!
</button>
</Demo>4. File Trees
Use Case: Visualizing directory structures, project layouts, or file organization.
<FileTree>
<FileTreeItem name="src" type="folder" defaultOpen>
<FileTreeItem name="components" type="folder">
<FileTreeItem name="Button.tsx" type="file" />
</FileTreeItem>
</FileTreeItem>
</FileTree>5. Steps
Use Case: Guiding readers through a sequential process or tutorial.
Install Dependencies
Run npm install to install the required packages.
Configure
Update your configuration file with the necessary API keys.
Run
Start the development server with npm run dev.
<Steps>
<Step title="Step 1">Description...</Step>
<Step title="Step 2">Description...</Step>
</Steps>6. Tabs
Use Case: Showing multiple options (e.g., npm vs yarn), different language implementations, or before/after code.
npm install react<Tabs defaultValue="npm">
<TabItem value="npm" label="npm">
npm install react
</TabItem>
<TabItem value="yarn" label="yarn">
yarn add react
</TabItem>
</Tabs>7. Badges
Use Case: Adding small labels or status indicators inline with text.
This feature is New and currently in Beta.
This feature is <Badge variant="success">New</Badge>8. Image Comparison
Use Case: Comparing two images, such as design iterations, optimization results, or visual changes.
<ImageComparison
before="/path/to/before.jpg"
after="/path/to/after.jpg"
alt="Comparison"
/>9. YouTube Embed
Use Case: Embedding video tutorials or demos directly into the post.
<YouTube id="dQw4w9WgXcQ" title="Video Title" />10. CodeSandbox
Use Case: Embedding live code environments for complex examples.
<CodeSandbox id="sandbox-id" title="Demo Title" />Conclusion
These components are designed to help you tell better stories. Use them to break up walls of text, provide clear examples, and engage your readers. Happy blogging!