CLI and init for accept-md: serve Markdown from Next.js via Accept: text/markdown
npm install accept-mdCLI for accept-md: scaffold middleware and a markdown handler in your Next.js app so that requests with Accept: text/markdown get a markdown version of the page.
Use via npx (no global install):
``bash`
npx accept-md init
Or install as a dev dependency:
`bash`
pnpm add -D accept-mdor npm install -D accept-md
Scans your Next.js project, detects App Router vs Pages Router and middleware location, and:
- Creates or updates middleware to rewrite Accept: text/markdown to the handlerapp/api/accept-md/route.ts
- Adds the handler at or route.js (App) or pages/api/accept-md/index.ts or index.js (Pages), depending on whether the project has TypeScriptaccept-md.config.js
- Creates accept-md-runtime
- Adds to dependencies
Options:
| Option | Description |
|--------|-------------|
| path | Project root (default: current directory) |--app-dir=
| | App directory (e.g. app or src/app) |--pages-dir=
| | Pages directory (e.g. pages or src/pages) |--middleware=
| | Middleware file (e.g. middleware.ts or src/middleware.ts) |
Reports detected router, routes, and potential issues (missing handler, config, etc.).
Patches .next/routes-manifest.json so it has a dataRoutes array. Use after next build if you hit “routesManifest.dataRoutes is not iterable” on Next.js 15+ with next start.
`ts`
import { runInit, runDoctor, runFixRoutes, detectProject } from 'accept-md';
- runInit(projectRoot, overrides?) – run init logic
- runDoctor(projectRoot) – run doctor, returns report
- runFixRoutes(projectRoot) – run fix-routes
- detectProject(projectRoot)` – detect app/pages/middleware paths
MIT · Repository