Skip to content

Commit f88637b

Browse files
JakubKontraclaude
andcommitted
feat: add Pages Router support with tests
Add `next-markdown-mirror/pages` entry point with middleware, API route handler, and llms.txt handlers for Next.js Pages Router. Includes 22 new tests and updated documentation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 163d404 commit f88637b

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/),
66
and this project adheres to [Semantic Versioning](https://semver.org/).
77

8+
## [1.1.0] - 2026-03-04
9+
10+
### Added
11+
12+
- **Pages Router support** — new `next-markdown-mirror/pages` entry point with full support for Next.js Pages Router (`pages/` directory)
13+
- `createMarkdownMiddleware()` — middleware that detects markdown requests and rewrites to `/api/md-mirror/...`
14+
- `createPagesMarkdownHandler()` — API route handler for `pages/api/md-mirror/[...path].ts`
15+
- `createPagesLlmsTxtHandler()` / `createPagesLlmsFullTxtHandler()` — API route handlers for llms.txt generation
16+
- Pages Router test coverage (22 tests across middleware, API route handler, and llms API route)
17+
818
## [1.0.1] - 2026-02-24
919

1020
### Added

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pnpm add next-markdown-mirror
4242
# or: bun add next-markdown-mirror
4343
```
4444

45-
### Next.js 16 setup (3 files)
45+
### App Router setup (Next.js 16+, 3 files)
4646

4747
**1. Proxy** — intercepts markdown requests and rewrites to the handler:
4848

@@ -79,6 +79,44 @@ export const GET = createLlmsTxtHandler({
7979
});
8080
```
8181

82+
### Pages Router setup (3 files)
83+
84+
**1. Middleware** — intercepts markdown requests and rewrites to the API route:
85+
86+
```ts
87+
// middleware.ts
88+
import { createMarkdownMiddleware } from 'next-markdown-mirror/pages';
89+
export default createMarkdownMiddleware();
90+
export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'] };
91+
```
92+
93+
**2. API route handler** — fetches your HTML internally and converts to Markdown:
94+
95+
```ts
96+
// pages/api/md-mirror/[...path].ts
97+
import { createPagesMarkdownHandler } from 'next-markdown-mirror/pages';
98+
99+
export default createPagesMarkdownHandler({
100+
baseUrl: process.env.NEXT_PUBLIC_SITE_URL!,
101+
});
102+
```
103+
104+
**3. llms.txt** — AI discovery file:
105+
106+
```ts
107+
// pages/api/llms.txt.ts
108+
import { createPagesLlmsTxtHandler } from 'next-markdown-mirror/pages';
109+
110+
export default createPagesLlmsTxtHandler({
111+
siteName: 'My Site',
112+
baseUrl: process.env.NEXT_PUBLIC_SITE_URL!,
113+
pages: [
114+
{ url: '/', title: 'Home', description: 'Welcome page' },
115+
{ url: '/about', title: 'About' },
116+
],
117+
});
118+
```
119+
82120
## How it works
83121

84122
```
@@ -148,7 +186,7 @@ See the [full configuration reference](https://jakubkontra.github.io/next-markdo
148186
| `extractJsonLd` | `boolean` | `true` | Extract JSON-LD as YAML frontmatter |
149187
| `baseUrl` | `string` || Base URL for resolving relative URLs |
150188
| `contentSignal` | `ContentSignal` || `Content-Signal` header value |
151-
| `routePrefix` | `string` | `'/md-mirror'` | Internal route prefix (proxy config) |
189+
| `routePrefix` | `string` | `'/md-mirror'` (App Router) / `'/api/md-mirror'` (Pages Router) | Internal route prefix |
152190

153191
## Contributing
154192

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-markdown-mirror",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Self-hosted Markdown for AI agents — serve Markdown instead of HTML when AI agents request it",
55
"type": "module",
66
"exports": {

0 commit comments

Comments
 (0)