MDX Notes
How to define and use metadata fields in MDX — titles, descriptions, authors, dates, tags, and custom fields that power your content system.
Understanding Document Metadata
Metadata is "data about data." It's the structured info that describes, classifies, and gives context to your document — without being part of the main content itself.
In MDX, metadata lives in frontmatter and does a lot of heavy lifting: powering navigation, enabling search, generating feeds, building SEO tags, and driving template logic.
When your metadata is well-structured, a collection of MDX files becomes a queryable content system. Your framework can automatically generate blog indexes, documentation sidebars, RSS feeds, and sitemaps — all from frontmatter.
Title Metadata
The title is the single most important piece of metadata. It shows up everywhere — browser tabs, search results, social shares, nav menus, content lists. Different contexts might need different versions of it.
---
# Primary title - displayed as the page heading
title: "Understanding TypeScript Generics"
# Short title for navigation and breadcrumbs
shortTitle: "Generics"
# Subtitle for additional context
subtitle: "From Basic Constraints to Advanced Patterns"
# Navigation label (used in sidebars)
sidebar_label: "TypeScript Generics"
# Browser tab title (if different from main title)
browserTitle: "TypeScript Generics Guide | DevDocs"
---Framework-Specific Title Handling
Next.js (App Router with generateMetadata):
Docusaurus:
---
title: Understanding TypeScript Generics
sidebar_label: Generics
# Docusaurus automatically uses title for SEO and browser tab
---Description Metadata
The description is a concise summary of what your page is about. It powers SEO meta tags, social media previews, content cards, and search result snippets.
---
# Primary description (aim for 150-160 characters for SEO)
description: "Master TypeScript generics with practical examples covering constraints, conditional types, mapped types, and real-world patterns."
# Extended description for content listings
excerpt: "TypeScript generics are one of the most powerful features of the type system. In this guide, we'll explore how generics enable you to write flexible, reusable code while maintaining full type safety."
# One-line summary for compact views
summary: "A complete guide to TypeScript generics"
---Tips for Good Descriptions
- Keep the primary description under 160 characters (that's the SEO sweet spot)
- Include your primary keywords naturally — don't stuff them
- Make it compelling. This is often the first text people see before clicking
- Don't just repeat the title word-for-word
- Use
excerptfor longer summaries in blog listing pages
Author Information
Author metadata can be as simple as a name or as detailed as a full bio with social links. Match it to what your site actually displays.
---
# Simple format
author: "Marcus Johnson"
# Detailed format
author:
name: "Marcus Johnson"
email: "marcus@techblog.dev"
url: "https://marcusjohnson.dev"
avatar: "/images/authors/marcus.jpg"
bio: "Senior Frontend Engineer at TechCorp. React enthusiast and OSS contributor."
twitter: "@marcusdev"
github: "marcusj"
# Multiple authors
authors:
- name: "Marcus Johnson"
role: "Primary Author"
avatar: "/images/authors/marcus.jpg"
- name: "Lisa Park"
role: "Technical Reviewer"
avatar: "/images/authors/lisa.jpg"
- name: "Dev Team"
role: "Contributors"
---Using Author Data in Components
// components/AuthorCard.jsx
export function AuthorCard({ author }) {
return (
<div className="author-card">
<img src={author.avatar} alt={author.name} />
<div>
<h3>{author.name}</h3>
<p>{author.bio}</p>
<div className="author-links">
{author.twitter && (
<a href={`https://twitter.com/${author.twitter}`}>Twitter</a>
)}
{author.github && (
<a href={`https://github.com/${author.github}`}>GitHub</a>
)}
</div>
</div>
</div>
);
}Date Metadata
Dates track the lifecycle of your content. Different date fields serve different purposes.
---
# When the document was first created (internal tracking)
createdAt: 2024-01-05
# When the content was published (public-facing)
publishedAt: 2024-01-15
# Last content modification (triggers "Updated" badge)
updatedAt: 2024-01-22
# Date displayed to readers (may differ from publishedAt for editorial reasons)
date: 2024-01-15
# Scheduled publication (for CMS workflows)
scheduledFor: 2024-02-01T09:00:00Z
# Content expiration (for time-sensitive content)
expiresAt: 2024-12-31
---Date Handling Across Frameworks
Gatsby (GraphQL date formatting):
query {
mdx(frontmatter: { slug: { eq: "my-post" } }) {
frontmatter {
date(formatString: "MMMM DD, YYYY")
updatedAt(fromNow: true) # "3 days ago"
}
}
}Next.js (manual formatting):
import { format, formatDistance } from 'date-fns';
function PostHeader({ frontmatter }) {
return (
<header>
<time dateTime={frontmatter.date}>
{format(new Date(frontmatter.date), 'MMMM d, yyyy')}
</time>
{frontmatter.updatedAt && (
<span className="updated">
Updated {formatDistance(new Date(frontmatter.updatedAt), new Date(), { addSuffix: true })}
</span>
)}
</header>
);
}Categories and Tags
Categories and tags are your content taxonomy — the system that helps readers find related content and helps you keep things organized.
---
# Single primary category (hierarchical)
category: "React"
# Subcategory for deeper classification
subcategory: "Hooks"
# Tags (flat, non-hierarchical, multiple allowed)
tags:
- react
- hooks
- state-management
- performance
# Series/collection grouping
series:
name: "React Fundamentals"
order: 3
total: 8
# Related content (manual curation)
relatedPosts:
- "intro-to-react-hooks"
- "useeffect-deep-dive"
- "custom-hooks-patterns"
---Building a Tag Index
Custom Metadata Fields
Beyond the standard stuff, you can add whatever metadata your content system needs.
---
# Content characteristics
difficulty: "intermediate"
readingTime: 8
wordCount: 2400
prerequisites:
- "basic-javascript"
- "intro-to-react"
# Visual presentation
heroImage: "/images/posts/generics-hero.png"
heroImageAlt: "TypeScript generics diagram showing type flow"
theme: "dark"
accentColor: "#3178c6"
# Interactive features
hasCodePlayground: true
hasQuiz: true
interactiveExamples: 3
# Content versioning
contentVersion: "2.1"
targetFrameworkVersion: "React 18+"
lastReviewedAt: 2024-01-20
reviewedBy: "tech-lead"
# Analytics and tracking
contentGroup: "tutorials"
experimentId: "new-tutorial-format-2024"
---Metadata Schemas
A formal schema keeps things consistent across all your content and catches errors at build time.
Using Metadata in Templates
Metadata drives your templates. One layout component adapts to whatever the frontmatter says:
Best Practices
- Define your schema first — Before writing content, decide what fields exist, which are required, and what values are valid.
- Stick with ISO dates —
YYYY-MM-DDor full datetime. No ambiguity, no timezone confusion.
- Keep author data DRY — Store detailed author info in a separate data file. Reference by ID in frontmatter instead of copy-pasting bios into every post.
- Control your tags — Without a controlled vocabulary, you'll end up with "react", "React", and "ReactJS" as three separate tags. Pick one and enforce it.
- Compute what you can —
readingTimeandwordCountcan be generated at build time. Don't make authors maintain these by hand.
- Version your schema — As your content system grows, track schema changes and migrate existing content when you add or rename fields.
- Write a field reference — Keep a doc showing all available fields, expected formats, and examples. Your content authors will thank you.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Document Metadata in MDX.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this MDX Tutorial topic.
Search Terms
mdx-tutorial, mdx tutorial, mdx, tutorial, frontmatter, metadata, document metadata in mdx
Related MDX Tutorial Topics