Next.js’s official MDX integration lets you import .mdx as components and export metadata alongside content. I used @next/mdx with the App Router and kept indexing simple by importing metadata directly from each MDX file. No extra build steps, no content database, and the sitemap pulls dates straight from the MDX front‑matter.Next.js’s official MDX integration lets you import .mdx as components and export metadata alongside content. I used @next/mdx with the App Router and kept indexing simple by importing metadata directly from each MDX file. No extra build steps, no content database, and the sitemap pulls dates straight from the MDX front‑matter.

How I Built a Simple MDX Blog in Next.js and why I chose native mdx over Contentlayer

There are many ways to host blogs with Next.js but I needed something fast & simple: plain MDX files, first‑party support, and zero extra content pipelines. No Contentlayer (which is unmaintained). No next-mdx-remote. No heavy weighted CMS systems.

\

TL;DR

  • Next.js’s official MDX integration lets you import .mdx as components and export metadata alongside content.
  • See doc here: https://nextjs.org/docs/pages/guides/mdx
  • I used @next/mdx with the App Router and kept indexing simple by importing metadata directly from each MDX file.
  • No extra build steps, no content database, and the sitemap pulls dates straight from the MDX front‑matter.

\

Why MDX + App Router?

  • Content is code: The App Router treats a folder as a route and page.mdx as a component. You get layouts, streaming, and RSC benefits for free.

  • First‑party MDX: The official plugin is maintained with Next.js and plays nicely with routing, metadata, and bundling.

  • Lower cognitive load: For a small product site, I don’t want a content compiler, watcher, or a GraphQL layer. A few MDX files and some imports are enough.

    \

    The Core Setup

  1. Add the official MDX plugin and let Next treat MD/MDX as pages.

next.config.js

import createMDX from '@next/mdx';  const withMDX = createMDX({   // Add remark/rehype plugins if/when needed   options: {     remarkPlugins: [],     rehypePlugins: [],   }, });  /** @type {import('next').NextConfig} */ const nextConfig = {   ...   pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'], };  export default withMDX(nextConfig); 

\

  1. Optionally customize how MDX renders components (I kept it minimal for now):

mdx-components.tsx

import type { MDXComponents } from 'mdx/types';  export function useMDXComponents(components: MDXComponents = {}): MDXComponents {   return {     ...components,   }; } 

\

  1. Type the metadata you export from MDX so TS understands it when imported elsewhere.

src/types/mdx.d.ts

declare module '*.mdx' {   import type { ComponentType } from 'react';   const MDXComponent: ComponentType<any>;   export default MDXComponent;   export const metadata: {     title?: string;     description?: string;     date?: string;     author?: string;     tags?: string[];   }; } 

\

  1. Create a post as a route. In the App Router, a folder is your slug and page.mdx is the page.

src/app/blog/how-to-export-ig-followers-tutorial/page.mdx

export const metadata = {   title: 'How to Export Instagram Followers (CSV, Excel, JSON)',   description: 'Step-by-step guide…',   date: '2025-08-28', };  import Image from 'next/image'; 

\

  1. Build a simple index page by importing metadata straight from MDX modules.

src/app/blog/page.tsx

import Link from 'next/link'; import { metadata as igExport } from './how-to-export-ig-followers-tutorial/page.mdx';  const posts = [   {     slug: 'how-to-export-ig-followers-tutorial',     title: igExport?.title ?? 'How to Export Instagram Followers',     description: igExport?.description,     date: igExport?.date,   }, ];  export default function BlogIndexPage() {   // Render cards linking to /blog/[slug] } 

\

  1. Keep your sitemap honest by importing the same metadata for lastModified.

src/app/sitemap.ts

import type { MetadataRoute } from 'next'; import { metadata as igExportPost } from './blog/how-to-export-ig-followers-tutorial/page.mdx'; import { getURL } from '@/utils/get-url';  export default function sitemap(): MetadataRoute.Sitemap {   return [     // …other routes     {       url: getURL('blog/how-to-export-ig-followers-tutorial'),       lastModified: igExportPost?.date ? new Date(igExportPost.date) : new Date(),       changeFrequency: 'weekly',       priority: 0.7,     },   ]; } 

\

The Aha Moments (and a few gotchas)

  • MDX as modules: You can import both the rendered component and named exports (metadata) from any .mdx file. That made the blog index and sitemap trivial.
  • Keep it typed: The *.mdx module declaration means TS won’t complain when you do import { metadata } from 'some-post/page.mdx'.
  • Less is more: I didn’t reach for Contentlayer because I don’t need filesystem crawling or transformations. With a handful of posts, a tiny array is fine.

\

Contentlayer vs. Native MDX

What Contentlayer gives you:

  • Schemas and types: Define required fields and get generated TypeScript. Build fails if a post is missing a title or date.
  • Content graph: Read files from a content/ directory, compute slugs/paths, and query everything in one place.
  • Computed fields: Derive readingTime, slug, canonical URLs, etc., at build time.
  • Good for docs sites: Multiple document types (Guides, API refs, Changelogs) with strict structure.

Native MDX strengths (why I chose it here):

  • Zero ceremony: No schema layer, no background watcher — just .mdx files and imports.
  • Co‑location: The post lives at app/blog/[slug]/page.mdx, same place users will visit.
  • Good enough typing: A tiny *.mdx module declaration plus optional Zod to validate metadata if you want stricter checks.

\

Market Opportunity
RWAX Logo
RWAX Price(APP)
$0.0002368
$0.0002368$0.0002368
+1.54%
USD
RWAX (APP) Live Price Chart
Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact [email protected] for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.

You May Also Like

XRP Price Prediction: Ripple CEO at Davos Predicts Crypto ATHs This Year – $5 XRP Next?

XRP Price Prediction: Ripple CEO at Davos Predicts Crypto ATHs This Year – $5 XRP Next?

XRP has traded near $1.90 as Ripple CEO Brad Garlinghouse has predicted from Davos that the crypto market will reach new highs this year. Analysts have pointed
Share
Coinstats2026/01/22 04:49
Fed Decides On Interest Rates Today—Here’s What To Watch For

Fed Decides On Interest Rates Today—Here’s What To Watch For

The post Fed Decides On Interest Rates Today—Here’s What To Watch For appeared on BitcoinEthereumNews.com. Topline The Federal Reserve on Wednesday will conclude a two-day policymaking meeting and release a decision on whether to lower interest rates—following months of pressure and criticism from President Donald Trump—and potentially signal whether additional cuts are on the way. President Donald Trump has urged the central bank to “CUT INTEREST RATES, NOW, AND BIGGER” than they might plan to. Getty Images Key Facts The central bank is poised to cut interest rates by at least a quarter-point, down from the 4.25% to 4.5% range where they have been held since December to between 4% and 4.25%, as Wall Street has placed 100% odds of a rate cut, according to CME’s FedWatch, with higher odds (94%) on a quarter-point cut than a half-point (6%) reduction. Fed governors Christopher Waller and Michelle Bowman, both Trump appointees, voted in July for a quarter-point reduction to rates, and they may dissent again in favor of a large cut alongside Stephen Miran, Trump’s Council of Economic Advisers’ chair, who was sworn in at the meeting’s start on Tuesday. It’s unclear whether other policymakers, including Kansas City Fed President Jeffrey Schmid and St. Louis Fed President Alberto Musalem, will favor larger cuts or opt for no reduction. Fed Chair Jerome Powell said in his Jackson Hole, Wyoming, address last month the central bank would likely consider a looser monetary policy, noting the “shifting balance of risks” on the U.S. economy “may warrant adjusting our policy stance.” David Mericle, an economist for Goldman Sachs, wrote in a note the “key question” for the Fed’s meeting is whether policymakers signal “this is likely the first in a series of consecutive cuts” as the central bank is anticipated to “acknowledge the softening in the labor market,” though they may not “nod to an October cut.” Mericle said he…
Share
BitcoinEthereumNews2025/09/18 00:23
Federal Reserve Lowers Interest Rates Again

Federal Reserve Lowers Interest Rates Again

The Federal Reserve has made the decision to lower interest rates by 25 basis points, signaling the possibility of further reductions later this year. This move comes as Fed officials appear divided on the future rate path, a divergence not seen in prior economic cycles.Continue Reading:Federal Reserve Lowers Interest Rates Again
Share
Coinstats2025/09/18 02:38