By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: How I Made My Next.js Blog Serve Markdown Files for Agent Experience SEO (AX-SEO) | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > How I Made My Next.js Blog Serve Markdown Files for Agent Experience SEO (AX-SEO) | HackerNoon
Computing

How I Made My Next.js Blog Serve Markdown Files for Agent Experience SEO (AX-SEO) | HackerNoon

News Room
Last updated: 2025/07/14 at 6:15 PM
News Room Published 14 July 2025
Share
SHARE

I’ll show you how to serve raw Markdown files in a Next.js blog using middleware and API routes, enabling Agent Experience SEO (AX-SEO).

AX-SEO focuses on optimizing content for AI agents, LLM-powered search engines, and automated crawlers that now play a major role in content discovery.

By the end of this post, you’ll be able to:

✅ Implement Next.js middleware for .md URL rewriting.

✅ Set up API routes to fetch and serve Markdown content.

✅ Optimize your blog for Agent Experience SEO (AI-driven search).

✅ Provide clean, structured data for AI-powered search engines.


Traditional SEO is no longer enough. AI search engines, LLM-powered assistants (ChatGPT, Perplexity, Google’s AI Overviews, etc.), and autonomous agents are now indexing and ranking content differently.

Why does AX-SEO matter?

  • AI agents prefer structured content – Raw Markdown is easier to parse than HTML.
  • LLMs use Markdown for training & retrieval – AI search engines extract structured text more efficiently.
  • AX-SEO improves discoverability – AI-driven platforms rank content based on how well agents can process it.

If you want your blog optimized for AI-driven search, this guide is for you!


Most blogs serve only HTML, making extracting structured information hard for AI tools. Common mistakes include:

❌ Not offering raw text formats – AI agents struggle with unnecessary markup.❌ Ignoring structured data for LLMs – AI search engines prioritize clean content.

This guide avoids these mistakes and ensures a future-proof content strategy for AI indexing.


How I Did It

Step 1: Middleware for .md Routing

I used Next.js Middleware to detect .md URLs and redirect them to an API route:

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

export function middleware(req: NextRequest) {
  const url = req.nextUrl.clone();

  if (url.pathname.endsWith(".md")) {
    url.pathname = `/api${url.pathname}`;
    return NextResponse.rewrite(url);
  }

  return NextResponse.next();
}

export const config = {
  matcher: ["/blog/:path*.md", "/projects/:path*.md"],
};

Step 2: API Route to Serve Markdown

Next, I created API endpoints to fetch Markdown content:

import { readMarkdown } from "@/server/read-markdown-file";
import { NextRequest } from "next/server";

export async function GET(_req: NextRequest, { params: { slug } }: { params: { slug: string } }) {
  return readMarkdown(slug);
}

Step 3: Fetching Markdown Content from CMS

The readMarkdown the function retrieves the raw Markdown content:

import useBlogSlug from "@/features/posts/hooks/useBlogSlug";
import { NextResponse } from "next/server";

export async function readMarkdown(slug: string) {
  try {
    const {
      post: {
        content: { markdown },
      },
    } = await useBlogSlug({ params: { slug: slug.replace(".md", "") } });

    return new NextResponse(markdown, {
      headers: {
        "Content-Type": "text/plain",
      },
    });
  } catch (error) {
    console.error("Error reading markdown file:", error);
    return new NextResponse(JSON.stringify({ message: "Markdown file not found" }), { status: 404 });
  }
}

Step 4: Adding a Markdown Link to the Blog

To make the Markdown file accessible, I added a link on each blog page:

<Link href={`/api/${params.type}/${params.slug}.md`} passHref>
  View Markdown
</Link>

Now, every post has a “View Markdown” button that links to the raw .md version.


How This Boosts Agent Experience SEO (AX-SEO)

  • ✅ AI-Optimized Content – Markdown is easier for AI bots to read than HTML.
  • ✅ AX-SEO Ready – AI-powered search engines prefer structured text for ranking and retrieval.
  • ✅ Faster AI Crawling – Lightweight Markdown improves indexing speed.
  • ✅ Better Content Extraction – LLMs can fetch raw text for RAG-based applications.
  • ✅ Scalable & Future-Proof – Works for blogs, docs, and AI knowledge bases.

Final Thoughts

With this approach, I made my Next.js blog serve Markdown dynamically, benefiting both humans and AI bots.

📂 Source Code: GitHub Repository🌍 Live Website: sm-y.dev

I hope this guide helps you boost your blog’s AX-SEO and AI search visibility! 🚀

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Galaxy Z Fold 7 vs. Z Fold 6: Slimmer Body, Bigger Screens and Slightly Higher Price
Next Article How to Avoid a Burst Pipe: Insulation and Other Preventive Measures
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

ESWIN Computing EBC77 RISC-V SBC To Support Ubuntu Linux
Computing
Mansion House 2025: UK tech embraces chancellor’s reforms – UKTN
News
The deluge of faster Qi2.2 wireless chargers is here
News
Samsung Galaxy Z Fold 7 vs Oppo Find N5: Which ultra-thin foldable wins?
Gadget

You Might also Like

Computing

ESWIN Computing EBC77 RISC-V SBC To Support Ubuntu Linux

2 Min Read
Computing

BMW, Mercedes, and Audi all pick Momenta to supply ADAS ·TechNode

3 Min Read
Computing

How to Implement AI Personalization in Your Marketing Strategy | Narrato

13 Min Read
Computing

AVVERIFIER Outpaces Mythril and ETHBMC in Smart Contract Vulnerability Detection | HackerNoon

11 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?