Serve markdown to LLMs instead of HTML
An autonomous codebase built by the Continue Software Factory
When an LLM visits your site, it gets this:
<div class="pricing-hero_container__x7z2k">
<div class="pricing-hero_gradient__m4k9p">
<h1 class="pricing-hero_title__j2x8n">
<span class="text-highlight_wrapper__k9m2x">Pricing</span>
</h1>
<div class="pricing-card_grid__p3k7m">
<div class="pricing-card_card__n8x2k" data-tier="free">
<!-- 200 more lines of div soup -->With next-geo, it gets this:
# Pricing
## Free
Get started at no cost.
- Up to 1,000 requests/month
- Community support
## Pro — $20/month
For growing teams.
- Unlimited requests
- Priority support
- Custom domainsDrop page.md files next to your page.tsx files and they're served automatically when an LLM requests your pages. When no page.md exists, pages are auto-converted from HTML to markdown on the fly.
This is Generative Engine Optimization — making your site readable by the AI agents and LLMs that increasingly drive traffic and surface your content.
- Quick start
- How it works
- Auto-conversion
- Configuration
- How detection works
- llms.txt
- Discovery Headers
- Caching & Security
- Utilities
- Redirects
- Route groups
- Contributing
- License
The easiest way to set up is with a coding agent. Install the skill and let it handle the wiring:
npx skills add continuedev/skills --skill setup-geoThen ask your agent: "Set up next-geo in this project."
npm install next-geoThree files to create/update — see Configuration below for details on each:
- Wrap your config — add
withGeo()tonext.config.js - Add middleware — create
middleware.tswithcreateGeoMiddleware() - Add route handler — create
app/api/geo/route.tswithcreateGeoHandler()
Then write page.md files next to any page.tsx:
app/
pricing/
page.tsx ← what browsers see
page.md ← what LLMs see
Test it:
curl -H "Accept: text/markdown" http://localhost:3000/pricing
# or
curl http://localhost:3000/pricing.mdLLMs and AI agents signal they want markdown in three ways:
- Accept header —
Accept: text/markdown(used by Claude Code, Cloudflare Markdown for Agents, etc.) - URL suffix — Append
.mdto any page URL (e.g.,example.com/pricing.md) - User-Agent — Known bot identifiers (ChatGPT-User, ClaudeBot, GPTBot, PerplexityBot, etc.)
When detected, requests are rewritten to an internal handler that serves your page.md or auto-converts the HTML.
Pages without a page.md file are automatically converted from HTML to clean markdown using Turndown. The converter:
- Extracts
<main>or<article>content (skips navigation, headers, footers) - Strips scripts, styles, and decorative elements
- Preserves headings, links, lists, code blocks, and tables
- Adds the page title as an
# h1if not already present
To disable auto-conversion:
createGeoHandler({ enableAutoConversion: false });createGeoMiddleware({
// Paths to skip (default: /api/*, /trpc/*, /_next/*, /monitoring*)
excludePaths: ["/api/*", "/admin/*"],
// Additional User-Agent patterns to treat as LLM bots
additionalBotUserAgents: ["MyCustomBot"],
// Disable the .md URL suffix convention (default: true)
enableMdSuffix: false,
});createGeoHandler({
// Disable auto-conversion fallback (default: true)
enableAutoConversion: false,
// Base URL for internal fetches during auto-conversion
internalBaseUrl: "http://localhost:3000",
// Add context for LLMs at the top/bottom of every response
preamble: (path) => `> Markdown for ${path}. Visit the full page for interactive content.`,
postamble: "---\nPowered by next-geo",
});| Signal | Example | Priority |
|---|---|---|
.md suffix |
GET /pricing.md |
Highest (explicit) |
| Accept header | Accept: text/markdown, text/html |
Medium (standard) |
| User-Agent | ClaudeBot/1.0 |
Lowest (fallback) |
The middleware checks signals in priority order and rewrites the first match. Normal browser requests are never affected.
Generate /llms.txt and /llms-full.txt following the llmstxt.org spec.
// app/llms.txt/route.ts
import { createLlmsTxtHandler } from "next-geo/llms-txt";
export const { GET } = createLlmsTxtHandler({
siteTitle: "My Site",
siteDescription: "What my site does",
baseUrl: "https://example.com",
entries: [
{ path: "/docs", title: "Documentation", description: "API reference and guides" },
],
});// app/llms-full.txt/route.ts
import { createLlmsFullTxtHandler } from "next-geo/llms-txt";
export const { GET } = createLlmsFullTxtHandler({
siteTitle: "My Site",
baseUrl: "https://example.com",
});The handlers auto-discover page.md files in your app directory, extract titles from # headings and descriptions from first paragraphs, and handle Next.js route groups (stripping (group-name) prefixes from URLs).
Advertise markdown availability via Link headers (RFC 8288):
import { addDiscoveryHeaders } from "next-geo/discovery";
// In your middleware or response handler:
addDiscoveryHeaders(response, pathname);
// Sets: Link: </pricing.md>; rel="alternate"; type="text/markdown"- Static
page.mdresponses:Cache-Control: public, max-age=300, s-maxage=3600 - Auto-converted responses:
Cache-Control: private, max-age=300(cookies are forwarded, so response may be user-specific) Vary: Acceptis added globally via the config wrapper so CDNs maintain separate cachesVary: User-Agentis added only to markdown responses- Auto-conversion guards against SSRF (same-host validation, same-host-only redirect following, size limits)
You can also use the detection logic directly:
import { isLlmRequest, detectLlmSignal } from "next-geo";
// Simple boolean check
if (isLlmRequest(pathname, acceptHeader, userAgent)) {
// ...
}
// Detailed signal info
const signal = detectLlmSignal(pathname, acceptHeader, userAgent);
// { type: 'accept-header', quality: 1.0 }
// { type: 'user-agent', botName: 'ClaudeBot' }
// { type: 'md-suffix', originalPath: '/pricing' }
// nullWhen multiple routes render the same content (e.g., / and /home both show the homepage), you can use a frontmatter redirect in page.md to serve another path's markdown instead of duplicating it:
---
redirect: /
---When the handler finds a redirect field, it resolves the target path's markdown (including its page.md or auto-conversion) and serves that. Redirect chains are followed up to 3 hops. Any frontmatter is stripped from served content — only the markdown body is returned.
This is useful for aliased routes, vanity URLs, or any case where two paths should serve identical LLM content.
Next.js route groups (e.g., (main-layout), (marketing)) are handled automatically. The handler scans all (...) directories at the app root to find page.md files regardless of which route group they belong to.
We welcome contributions! See CONTRIBUTING.md for development setup, project structure, and the PR process.
Apache-2.0 — see LICENSE for details. Copyright (c) 2025 Continue Dev, Inc.
Built by Continue