@vllnt/next-llms 0.1.0 → 0.1.1-canary.253bc5f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,7 +4,63 @@ All notable changes to this project are documented here. The format is based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [0.1.1] - 2026-11-28
8
+
9
+ Documentation and tooling release. The published code, exports and types are
10
+ unchanged from 0.1.0; only TSDoc comments in `dist/` and `src/`, and the
11
+ matching source maps, differ.
12
+
13
+ ### Changed
14
+
15
+ - `llms.txt` links the files shipped in the package (`README.md`, `docs/API.md`,
16
+ `CHANGELOG.md`, `LICENSE`) by relative path, so they match the installed
17
+ version, adds a "For coding agents" note, and ends with an "Ecosystem" list:
18
+ the package page, the release feed, the vllnt oss index, package search, vllnt
19
+ and the author. The README gains matching "For coding agents" and "Related
20
+ packages" sections and adds a "Links" section before "License", in place of
21
+ "Author", with the package page, release feed, oss index, package search,
22
+ source, community, vllnt.com, author and sponsor links. The entry module's
23
+ TSDoc links the package page.
24
+ - `package.json` `homepage` points to
25
+ `https://oss.vllnt.com/packages/next-llms`.
26
+ - Every push to `main` that changes the package or its shipped docs publishes a
27
+ canary.
28
+ - The README is rewritten for coding agents: a one-sentence summary, then "For
29
+ coding agents", "When to use", "Install", "Quick start", "API", "Common
30
+ tasks", "Errors and fixes", "Limits and gotchas" and "Compatibility". The
31
+ examples are self-contained, and "Errors and fixes" lists every error the
32
+ package raises itself or returns, plus the Next.js `500` for malformed
33
+ percent-encoding.
34
+ - `package.json` `description` and `keywords` name what the package does and its
35
+ stack. `llms.txt` carries the same summary and use cases and links the API
36
+ reference and the errors table.
37
+ - `docs/API.md` gives each exported type its own heading and replaces the
38
+ undefined `getDoc` placeholder with a self-contained example; so does the
39
+ `createMarkdownRoute` TSDoc example. It no longer says to authorize in the
40
+ resolver, which only receives the slug, and no longer claims Remix, Hono and
41
+ Deno support, which is untested. The docs state that CI tests only Node.js 24
42
+ and that Next.js 16.4.6 was checked by hand.
43
+ - The docs state that empty segments from `//` are dropped (Next.js first
44
+ answers `308` with the single-slash path) and only a segment left empty by
45
+ stripping `.md` gets `400`, that `.md` is stripped before the segments are
46
+ URL-decoded, that `cacheControl: ""` sends an empty `Cache-Control` header,
47
+ which `Headers` message Node.js 18.0.0 gives for a bad `cacheControl`, that
48
+ the slug includes any route prefix, that only a lowercase `.md` is stripped,
49
+ that serving `/` needs `app/[[...slug]]`, and that the output ends with the
50
+ trailing newline of `details` when no section follows.
51
+ - Internal: development tooling moves to eslint 10, pnpm 12 and
52
+ `@vllnt/typescript` 3; CI and every publish test the packed tarball in a clean
53
+ project first; there is no version-update bot, and CI and publish set up pnpm
54
+ through Corepack, so every action in `ci.yml` and `publish.yml` is GitHub's
55
+ own and pinned to a commit.
56
+
57
+ ### Fixed
58
+
59
+ - The `llms.txt` link-list example showed a GitHub URL instead of `url`.
60
+ - `llms.txt` now documents the `400` response for unsafe paths and the `404` for
61
+ any non-string resolver result.
62
+ - README links to `SECURITY.md` and `CONTRIBUTING.md`, which are not in the
63
+ package, now point to GitHub so they resolve from `node_modules`.
8
64
 
9
65
  ## [0.1.0] - 2026-11-23
10
66
 
@@ -15,9 +71,9 @@ version.
15
71
  ### Added
16
72
 
17
73
  - First stable release of `@vllnt/next-llms`.
18
- - `generateLlmsText(config)` — generate a spec-compliant `llms.txt` index: an
19
- `#` title, a `>` blockquote, optional free prose, `## Section` link lists, and
20
- a droppable `## Optional` section (per the llmstxt.org specification).
74
+ - `generateLlmsText(config)` — generate an `llms.txt` index in the llmstxt.org
75
+ shape: an `#` title, a `>` blockquote, optional free prose, `## Section` link
76
+ lists, and a droppable `## Optional` section.
21
77
  - `createMarkdownRoute(resolver, options?)` — a Web-standard
22
78
  `(request) => Promise<Response>` App Router route handler that strips a
23
79
  trailing `.md`, resolves the slug, and returns `text/markdown` with a
@@ -29,10 +85,10 @@ version.
29
85
  ### Security
30
86
 
31
87
  - `createMarkdownRoute` now answers `400` without calling the resolver when the
32
- path has malformed percent-encoding (previously an unhandled `URIError`) or a
33
- decoded segment that is empty, `.`, `..`, or contains `/`, `\` or a NUL byte
34
- (for example `..%2F..%2Fsecret`), so resolvers that map slugs to files never
35
- receive a traversal sequence.
88
+ path has malformed percent-encoding (previously an unhandled `URIError`), a
89
+ segment left empty by stripping `.md`, or a decoded segment that is `.`, `..`,
90
+ or contains `/`, `\` or a NUL byte (for example `..%2F..%2Fsecret`), so
91
+ resolvers that map slugs to files never receive a traversal sequence.
36
92
  - `createMarkdownRoute` answers `404` when the resolver returns a non-string
37
93
  value such as `undefined` (previously an empty `200`), sets
38
94
  `X-Content-Type-Options: nosniff`, and throws a `TypeError` at creation for an
package/README.md CHANGED
@@ -1,131 +1,254 @@
1
- <!-- Badges -->
1
+ # @vllnt/next-llms
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@vllnt/next-llms.svg)](https://www.npmjs.com/package/@vllnt/next-llms)
4
- [![CI](https://github.com/vllnt/next-llms/actions/workflows/ci.yml/badge.svg)](https://github.com/vllnt/next-llms/actions/workflows/ci.yml)
5
- [![license](https://img.shields.io/npm/l/@vllnt/next-llms.svg)](./LICENSE)
3
+ Generate an llms.txt file and serve pages as Markdown from Next.js App Router
4
+ route handlers, using Web-standard Request and Response and no dependencies.
6
5
 
7
- # @vllnt/next-llms
6
+ ## For coding agents
7
+
8
+ Docs ship in `node_modules/@vllnt/next-llms/` (`README.md`, `docs/API.md`,
9
+ `llms.txt`, `CHANGELOG.md`, `src/`) and match the installed version. The bundled
10
+ `llms.txt` describes this package; it is not output of `generateLlmsText`.
11
+
12
+ ## When to use
13
+
14
+ - Use it when your Next.js site should serve an `/llms.txt` link index.
15
+ - Use it when you have Markdown for your pages and want it at `.md` URLs.
16
+ - Do not use it to build the link list from your routes; build it in your code.
17
+ - Do not use it to convert HTML to Markdown; use a converter such as `turndown`.
18
+ - Do not use it for `llms-full.txt`; concatenate your pages in your own route.
8
19
 
9
- Make your Next.js site legible to AI agents — generate a spec-compliant
10
- `llms.txt` manifest and serve any page as raw markdown.
20
+ ## Install
21
+
22
+ ```bash
23
+ pnpm add @vllnt/next-llms
24
+ ```
25
+
26
+ ## Quick start
11
27
 
12
28
  ```ts
13
- // app/llms.txt/route.ts
29
+ // app/[...slug]/route.ts — serves /docs/intro.md (and /docs/intro)
30
+ import { createMarkdownRoute } from "@vllnt/next-llms";
31
+
32
+ const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
33
+
34
+ export const GET = createMarkdownRoute((slug) => pages[slug.join("/")] ?? null);
35
+ ```
36
+
37
+ ```ts
38
+ // app/llms.txt/route.ts — serves /llms.txt
14
39
  import { generateLlmsText } from "@vllnt/next-llms";
15
40
 
16
- export function GET() {
17
- return new Response(
18
- generateLlmsText({
19
- title: "Acme",
20
- summary: "Acme is a widget API.",
21
- sections: [
22
- {
23
- title: "Docs",
24
- links: [{ title: "Quickstart", url: "/docs/quickstart.md" }],
25
- },
26
- ],
27
- }),
28
- { headers: { "Content-Type": "text/plain; charset=utf-8" } },
29
- );
41
+ export function GET(): Response {
42
+ const text = generateLlmsText({
43
+ title: "Acme",
44
+ summary: "Acme is a widget API.",
45
+ sections: [
46
+ { title: "Docs", links: [{ title: "Intro", url: "/docs/intro.md" }] },
47
+ ],
48
+ });
49
+ return new Response(text, {
50
+ headers: { "Content-Type": "text/plain; charset=utf-8" },
51
+ });
30
52
  }
31
53
  ```
32
54
 
33
- Emit the `llms.txt` index and expose any page's markdown at `/path.md` so agents
34
- skip HTML parsing. Zero runtime dependencies — pure Web-standard APIs that run
35
- in any Next.js runtime (and Remix, Hono, Deno, …).
36
-
37
- ## Features
55
+ [![npm](https://img.shields.io/npm/v/@vllnt/next-llms.svg)](https://www.npmjs.com/package/@vllnt/next-llms)
56
+ [![CI](https://github.com/vllnt/next-llms/actions/workflows/ci.yml/badge.svg)](https://github.com/vllnt/next-llms/actions/workflows/ci.yml)
57
+ [![license](https://img.shields.io/npm/l/@vllnt/next-llms.svg)](./LICENSE)
38
58
 
39
- - **Spec-compliant `llms.txt`** — `generateLlmsText` emits the llmstxt.org
40
- shape: an `#` title, a `>` blockquote, `## Section` link lists, and a
41
- droppable `## Optional` section.
42
- - **Raw-markdown routes** — `createMarkdownRoute` serves any page as
43
- `text/markdown`, stripping a trailing `.md` and resolving the slug through
44
- your own content source.
45
- - **Zero dependencies** — pure TypeScript over Web `Request` / `Response`;
46
- nothing added to your bundle.
47
- - **Runtime-agnostic** — the route handler imports nothing from `next`; it runs
48
- on the Edge, Node, or any Web-standard runtime.
49
- - **Typed end to end** — concrete config types guide correct usage; no `any`.
50
- - **Cache-friendly** — sensible `Cache-Control` defaults, overridable per route.
59
+ ## API
51
60
 
52
- ## Installation
61
+ Everything is exported from the package root. Full reference:
62
+ [docs/API.md](docs/API.md).
53
63
 
54
- ```bash
55
- pnpm add @vllnt/next-llms
56
- ```
64
+ | Export | Kind | What it is |
65
+ | -------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
66
+ | [`generateLlmsText(config)`](docs/API.md#generatellmstextconfig) | function | Returns the `llms.txt` text as a `string`; adds no trailing newline (a `details` that ends with one keeps it when no section follows it). |
67
+ | [`createMarkdownRoute(resolver, options?)`](docs/API.md#createmarkdownrouteresolver-options) | function | Returns a `(request: Request) => Promise<Response>` route handler. |
68
+ | [`LlmsConfig`](docs/API.md#llmsconfig) | type | Input of `generateLlmsText`: title, summary, details, sections, optional. |
69
+ | [`LlmsSection`](docs/API.md#llmssection) | type | One `## {title}` section and its links. |
70
+ | [`LlmsLink`](docs/API.md#llmslink) | type | One `- [title](url): notes` line. |
71
+ | [`MarkdownResolver`](docs/API.md#markdownresolver) | type | `(slug: string[]) => string \| null \| Promise<string \| null>`. |
72
+ | [`MarkdownRouteOptions`](docs/API.md#markdownrouteoptions) | type | `{ cacheControl?: string }` for `createMarkdownRoute`. |
57
73
 
58
- Node.js `>=18`; no peer dependencies (the package imports nothing from `next` or
59
- `react`). Every push to `main` can publish a prerelease to the `canary` channel
60
- (`pnpm add @vllnt/next-llms@canary`); stable releases are published from a
61
- `vX.Y.Z` tag. The older `generateLlmsFullText` API from early canary builds is
62
- not part of the stable API; use the two exports below.
74
+ ## Common tasks
63
75
 
64
- ## Usage
76
+ Serve Markdown files from a `content/` folder (Node.js runtime). The resolver
77
+ never receives a `.` or `..` segment or one containing `/`, `\` or NUL: URL
78
+ parsing resolves dot segments first (`/docs/../x` gives `["x"]`) and the route
79
+ answers `400` for the rest.
65
80
 
66
81
  ```ts
67
- // app/[...slug]/route.ts — serve any page as raw markdown
82
+ // app/[...slug]/route.ts — /docs/intro.md reads content/docs/intro.md
83
+ import { readFile } from "node:fs/promises";
84
+ import { join } from "node:path";
85
+
68
86
  import { createMarkdownRoute } from "@vllnt/next-llms";
69
87
 
88
+ const CONTENT_DIR = join(process.cwd(), "content");
89
+
70
90
  export const GET = createMarkdownRoute(async (slug) => {
71
- const doc = await getDoc(slug.join("/")); // your content source
72
- return doc?.markdown ?? null; // null → 404
91
+ try {
92
+ return await readFile(`${join(CONTENT_DIR, ...slug)}.md`, "utf8");
93
+ } catch {
94
+ return null; // any read error becomes a 404
95
+ }
73
96
  });
74
97
  ```
75
98
 
76
- `/docs/intro.md` resolves the slug `["docs", "intro"]` and returns the markdown
77
- with `Content-Type: text/markdown`, or `404` when the resolver returns `null`.
99
+ Mount the route under a prefix. The slug is built from the full request path, so
100
+ it includes the prefix; drop it yourself.
101
+
102
+ ```ts
103
+ // app/md/[...slug]/route.ts — /md/docs/intro.md gives ["md", "docs", "intro"]
104
+ import { createMarkdownRoute } from "@vllnt/next-llms";
105
+
106
+ const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
107
+
108
+ export const GET = createMarkdownRoute(
109
+ (slug) => pages[slug.slice(1).join("/")] ?? null,
110
+ );
111
+ ```
112
+
113
+ Serve private content. The resolver only receives the slug, so check the request
114
+ in your own `GET` and turn off public caching.
78
115
 
79
- ## API Reference
116
+ ```ts
117
+ // app/[...slug]/route.ts
118
+ import { createMarkdownRoute } from "@vllnt/next-llms";
80
119
 
81
- | Export | Kind | Result |
82
- | ----------------------------------------- | -------- | ----------------------------------------- |
83
- | `generateLlmsText(config)` | function | `string` — the `llms.txt` index |
84
- | `createMarkdownRoute(resolver, options?)` | factory | `(request: Request) => Promise<Response>` |
120
+ const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
85
121
 
86
- Full reference: [docs/API.md](docs/API.md). Also see the [LLM index](llms.txt),
87
- [changelog](CHANGELOG.md), and
88
- [issue tracker](https://github.com/vllnt/next-llms/issues).
122
+ const serve = createMarkdownRoute((slug) => pages[slug.join("/")] ?? null, {
123
+ cacheControl: "private, no-store",
124
+ });
125
+
126
+ export async function GET(request: Request): Promise<Response> {
127
+ const token = process.env.DOCS_TOKEN;
128
+ if (!token || request.headers.get("authorization") !== `Bearer ${token}`) {
129
+ return new Response("Unauthorized", { status: 401 });
130
+ }
131
+ return serve(request);
132
+ }
133
+ ```
134
+
135
+ Run on the Edge runtime: add `export const runtime = "edge";` to the route file.
136
+ The package uses no Node.js APIs. Next.js 16.4.6 serves it but warns at build
137
+ time that the Edge Runtime is deprecated.
138
+
139
+ ## Errors and fixes
140
+
141
+ | Error or response | Cause | Fix |
142
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
143
+ | `TypeError: title must be a non-empty string` | `generateLlmsText` got a missing, non-string or blank `title`. | Pass a non-empty `title`. |
144
+ | `TypeError: section title must be a non-empty string` | A `sections[].title` is missing or blank. | Give every section a title. |
145
+ | `TypeError: link title must be a non-empty string` | A link in `sections[].links` or `optional` has a `title` that is missing, not a string or blank. | Give every link a title. |
146
+ | `TypeError: link url must be a non-empty string` | A link `url` is missing, not a string or blank. | Give every link a `url`. |
147
+ | `TypeError: link url must not use a javascript:, data: or vbscript: scheme` | A link `url` starts with one of those schemes (case and control characters ignored). | Use an `http(s)` or relative URL. |
148
+ | `TypeError` from `new Headers` (Node.js 22 and 24: `Headers.append: "<value>" is an invalid header value.` or `Cannot convert argument to a ByteString ...`) | `createMarkdownRoute` got a `cacheControl` with a line break inside the value, a NUL or a character above U+00FF (`Headers` trims leading and trailing whitespace, including line breaks). It is thrown when the route is created, not per request. Node.js 18.0.0 throws `TypeError: Invalid character in header content ["Cache-Control"]` for every bad value. | Pass a plain ASCII header value. |
149
+ | `400` `Bad Request` (`text/plain`) | A segment is left empty by stripping `.md` (`/.md`, `/docs/.md`), a segment is `.` or `..` after stripping `.md` and decoding (`/docs/...md`), a decoded segment contains `/`, `\` or NUL (for example `/docs/..%2Fsecret.md`), or, outside Next.js, the path has malformed percent-encoding. The resolver is not called. URL parsing resolves plain `.` and `..` segments first (`/docs/../x` gives `["x"]`), and empty segments from `//` are dropped, not rejected (`/docs//intro.md` gives `["docs", "intro"]`). | Request a path whose segments are plain names. |
150
+ | `404` `Not Found` (`text/plain`) | The resolver returned `null` or any non-string (such as `undefined`). | Return the Markdown `string`; return `null` only for missing pages. |
151
+ | Rejected promise (Next.js answers `500`) | The resolver threw or rejected; the handler does not catch it. | Catch errors in the resolver and return `null` or a string. |
152
+ | `500` `Internal Server Error` from Next.js | In Next.js, a path with malformed percent-encoding (such as `/docs/%E0.md`) fails inside Next.js before the route runs. | Nothing to fix in the route; request a correctly encoded path. |
153
+ | Other `TypeError`s, such as `Cannot read properties of undefined (reading 'map')` | Input that does not match the types, for example from plain JavaScript: a section without `links`, or no config at all. `createMarkdownRoute(resolver, null)` throws `Cannot read properties of null (reading 'cacheControl')` at creation; a resolver that is not a function rejects with `resolver is not a function` on each request (Next.js answers `500`). | Pass values that match the exported types (`LlmsConfig`, `MarkdownResolver`, `MarkdownRouteOptions`). |
154
+
155
+ ## Limits and gotchas
156
+
157
+ - The slug comes from the full request path, not from Next.js route params: a
158
+ route under `app/md/` gets `"md"` as its first segment.
159
+ - Only a lowercase trailing `.md` on the last segment is removed. `/docs/intro`
160
+ and `/docs/intro.md` give the same slug; `/docs/INTRO.MD` gives `"INTRO.MD"`.
161
+ - `app/[...slug]` does not match `/`. Use `app/[[...slug]]` to also serve `/`
162
+ (slug `[]`).
163
+ - A dynamic page route wins over a root catch-all: with
164
+ `app/blog/[slug]/page.tsx`, `/blog/post.md` renders that page, not your
165
+ Markdown.
166
+ - A root catch-all answers every unmatched URL with a `text/plain` 404, not your
167
+ site's HTML not-found page. Mount it under a prefix to avoid that.
168
+ - Default `Cache-Control` is public:
169
+ `public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800`.
170
+ - `cacheControl: ""` sends an empty `Cache-Control` header; it does not fall
171
+ back to the default. Leave the option out to get the default.
172
+ - An empty string from the resolver is content: `200` with an empty body.
173
+ - `generateLlmsText` adds no trailing newline; a `details` that ends with one
174
+ keeps it when no section (from `sections` or `optional`) follows it. A
175
+ `summary`, `details` or
176
+ `notes` that is `""`, and an empty `optional` array, are left out without a
177
+ warning. Whitespace-only `notes` are also left out, but a whitespace-only
178
+ `summary` renders an empty `> ` line. A section with no links renders only its
179
+ heading.
180
+ - `details` is inserted as-is, even when it is only whitespace; it is not
181
+ escaped.
182
+ - In Next.js, a path with malformed percent-encoding gets Next's own `500`
183
+ before the route runs, so the handler's `400` for it is only seen outside
184
+ Next.js.
185
+ - In Next.js, a path with `//` gets a `308` redirect to the single-slash path
186
+ (`/docs//intro.md` to `/docs/intro.md`) before the route runs.
187
+ - Only `GET` is created. In Next.js, `HEAD` is answered from `GET`, `OPTIONS`
188
+ gets `204` with `Allow: GET, HEAD, OPTIONS`, and other methods get `405`.
189
+ - ESM only; there is no CommonJS build.
190
+
191
+ ## Compatibility
192
+
193
+ - Peer dependencies: none. Runtime dependencies: none.
194
+ - Node.js `>=18` (`engines`). Needs the global `Request`, `Response`, `URL` and
195
+ `Headers`. CI runs the tests on Node.js 24 only, so 18 to 23 are not tested.
196
+ - Next.js is not imported. The package was checked by hand with Next.js 16.4.6
197
+ App Router route handlers on the Node.js and Edge runtimes (Next.js marks the
198
+ Edge Runtime deprecated); CI runs the unit tests outside Next.js.
199
+ - Other runtimes and frameworks with the same Web APIs (Deno, Bun, Hono, Remix)
200
+ are not tested.
201
+ - Release channels: stable on `latest`, prereleases on `canary`
202
+ (`pnpm add @vllnt/next-llms@canary`). `generateLlmsFullText` from early canary
203
+ builds is not part of the stable API.
204
+
205
+ ## Testing
206
+
207
+ ```bash
208
+ pnpm test # single run
209
+ pnpm test:coverage # enforced 100% on covered files
210
+ ```
89
211
 
90
212
  ## Security
91
213
 
92
214
  - No secrets touched — the package generates text and serves whatever your
93
215
  resolver returns.
94
- - Your resolver is the boundary — authorize the slug before returning content.
95
- The route rejects malformed percent-encoding and slug segments that are empty,
96
- `.`, `..`, or contain `/`, `\` or NUL (`400`), but you still own how a slug
97
- maps to a file or record.
216
+ - Your resolver is the boundary — decide which slugs it may return. It receives
217
+ only the slug, so check the request yourself for per-user access (see
218
+ [Common tasks](#common-tasks)).
98
219
  - `generateLlmsText` escapes link titles and URLs and collapses line breaks, and
99
220
  rejects blank titles/URLs and `javascript:`, `data:` or `vbscript:` URLs with
100
221
  a `TypeError`.
101
- - Successful responses default to **public caching** (one hour in browsers, one
102
- day in shared caches). For private or personalized content, explicitly pass
103
- `{ cacheControl: "private, no-store" }`; authorization alone does not disable
104
- caching.
222
+ - Successful responses default to **public caching**. For private or
223
+ personalized content, pass `{ cacheControl: "private, no-store" }`;
224
+ authorization alone does not disable caching.
105
225
 
106
- See [docs/API.md](docs/API.md) and the [security reporting policy](SECURITY.md).
226
+ See [docs/API.md](docs/API.md) and the
227
+ [security reporting policy](https://github.com/vllnt/next-llms/blob/main/SECURITY.md).
107
228
 
108
- ## Testing
229
+ ## Related packages
109
230
 
110
- ```bash
111
- pnpm test # single run
112
- pnpm test:coverage # enforced 100% on covered files
113
- ```
231
+ No other `@vllnt` package covers `llms.txt` manifests or markdown routes. See
232
+ every package at [oss.vllnt.com/packages](https://oss.vllnt.com/packages).
114
233
 
115
234
  ## Contributing
116
235
 
117
- See [CONTRIBUTING.md](CONTRIBUTING.md).
118
-
119
- ## Author
236
+ See
237
+ [CONTRIBUTING.md](https://github.com/vllnt/next-llms/blob/main/CONTRIBUTING.md).
120
238
 
121
- Built by [bntvllnt](https://github.com/bntvllnt) ·
122
- [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
239
+ ## Links
123
240
 
124
- Part of the [@vllnt](https://github.com/vllnt) open-source fleet —
125
- [vllnt.com](https://vllnt.com)
126
-
127
- If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
241
+ - Docs and changelog: [oss.vllnt.com/packages/next-llms](https://oss.vllnt.com/packages/next-llms) · [release feed](https://oss.vllnt.com/packages/next-llms/rss.xml)
242
+ - All @vllnt packages: [oss.vllnt.com](https://oss.vllnt.com) · [search packages and docs on index.vllnt.com](https://index.vllnt.com)
243
+ - Source and issues: [GitHub](https://github.com/vllnt/next-llms) · [issues](https://github.com/vllnt/next-llms/issues) · [npm](https://www.npmjs.com/package/@vllnt/next-llms)
244
+ - Questions and updates: [Discord](https://bntvllnt.com/discord) · [X @bntvllnt](https://x.com/bntvllnt)
245
+ - Company and author: [vllnt.com](https://vllnt.com) · [bntvllnt.com](https://bntvllnt.com) · [GitHub @bntvllnt](https://github.com/bntvllnt) · [LinkedIn](https://linkedin.com/in/bntvllnt)
246
+ - Sponsor: [GitHub Sponsors](https://github.com/sponsors/bntvllnt)
128
247
 
129
248
  ## License
130
249
 
131
250
  MIT — see [LICENSE](LICENSE).
251
+
252
+ ---
253
+
254
+ Part of [vllnt open source](https://oss.vllnt.com) · [Package page](https://oss.vllnt.com/packages/next-llms) · [vllnt.com](https://vllnt.com) · Built by [bntvllnt](https://bntvllnt.com)
package/dist/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Generate an `llms.txt` file and serve pages as Markdown from Next.js App
3
+ * Router route handlers.
4
+ *
5
+ * @packageDocumentation
6
+ * @see https://oss.vllnt.com/packages/next-llms
7
+ */
1
8
  export { generateLlmsText } from "./llms-text.js";
2
9
  export { createMarkdownRoute } from "./markdown-route.js";
3
10
  export type { LlmsConfig, LlmsLink, LlmsSection, MarkdownResolver, MarkdownRouteOptions, } from "./types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Generate an `llms.txt` file and serve pages as Markdown from Next.js App
3
+ * Router route handlers.
4
+ *
5
+ * @packageDocumentation
6
+ * @see https://oss.vllnt.com/packages/next-llms
7
+ */
1
8
  export { generateLlmsText } from "./llms-text.js";
2
9
  export { createMarkdownRoute } from "./markdown-route.js";
3
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -5,7 +5,9 @@ import type { LlmsConfig } from "./types.js";
5
5
  * prose, `## {section}` link lists, and a droppable `## Optional` section.
6
6
  *
7
7
  * @param config - The manifest content.
8
- * @returns The `llms.txt` file contents (no trailing newline).
8
+ * @returns The `llms.txt` file contents. No trailing newline is added; a
9
+ * `details` value that ends with one keeps it when no section (from `sections`
10
+ * or `optional`) follows it.
9
11
  * @throws {TypeError} When a title or link URL is blank, or a URL uses a
10
12
  * `javascript:`, `data:` or `vbscript:` scheme. Line breaks inside titles,
11
13
  * summaries and notes are collapsed to spaces, `[`, `]` and `\` in link titles
@@ -1 +1 @@
1
- {"version":3,"file":"llms-text.d.ts","sourceRoot":"","sources":["../src/llms-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,YAAY,CAAC;AAqDpE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAU3D"}
1
+ {"version":3,"file":"llms-text.d.ts","sourceRoot":"","sources":["../src/llms-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,YAAY,CAAC;AAqDpE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAU3D"}
package/dist/llms-text.js CHANGED
@@ -45,7 +45,9 @@ function renderSection(section) {
45
45
  * prose, `## {section}` link lists, and a droppable `## Optional` section.
46
46
  *
47
47
  * @param config - The manifest content.
48
- * @returns The `llms.txt` file contents (no trailing newline).
48
+ * @returns The `llms.txt` file contents. No trailing newline is added; a
49
+ * `details` value that ends with one keeps it when no section (from `sections`
50
+ * or `optional`) follows it.
49
51
  * @throws {TypeError} When a title or link URL is blank, or a URL uses a
50
52
  * `javascript:`, `data:` or `vbscript:` scheme. Line breaks inside titles,
51
53
  * summaries and notes are collapsed to spaces, `[`, `]` and `\` in link titles
@@ -1 +1 @@
1
- {"version":3,"file":"llms-text.js","sourceRoot":"","sources":["../src/llms-text.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,iCAAiC,CAAC;AAC5D,0GAA0G;AAC1G,MAAM,YAAY,GAAG,mBAAmB,CAAC;AACzC,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAEjD,+EAA+E;AAC/E,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,IAAI,SAAS,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IACpC,IAAI,SAAS,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IACpC,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,yEAAyE;AACzE,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC;AAED,yDAAyD;AACzD,SAAS,YAAY,CAAC,KAAc,EAAE,KAAa;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,SAAS,CAAC,GAAY;IAC7B,MAAM,IAAI,GAAG,YAAY,CAAC,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C,EAAE,CAAC;IACrE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,OAAO;QACL,KAAK,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;QAC1C,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC;QAC7C,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAC/C,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;YAChE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjB,CAAC"}
@@ -3,17 +3,21 @@ import type { MarkdownResolver, MarkdownRouteOptions } from "./types.js";
3
3
  * Create a Next.js App Router route handler that serves a slug's markdown
4
4
  * content. Mount it at a catch-all route (`app/[...slug]/route.ts`). The handler
5
5
  * is a pure Web-standard `(request) => Promise<Response>` — it imports nothing
6
- * from `next` and runs in any Web runtime.
6
+ * from `next` and uses only Web-standard APIs.
7
7
  *
8
- * - Strips a trailing `.md` from the path (`/docs/intro.md` resolves the slug
9
- * `["docs", "intro"]`).
8
+ * - Strips a trailing lowercase `.md` from the path (`/docs/intro.md`
9
+ * resolves the slug `["docs", "intro"]`).
10
10
  * - Returns `200` with `Content-Type: text/markdown; charset=utf-8` and a
11
11
  * `Cache-Control` header when the resolver returns a string.
12
12
  * - Returns `404` (plain text) when the resolver returns `null` (or any
13
13
  * non-string value, such as `undefined` from a missing map entry).
14
14
  * - Returns `400` (plain text) without calling the resolver when the path has
15
- * malformed percent-encoding or a segment that is empty, `.`, `..`, or
16
- * contains `/`, `\` or a NUL byte.
15
+ * malformed percent-encoding, a segment left empty by stripping `.md`
16
+ * (`/docs/.md`), or a decoded segment that is `.`, `..`, or contains `/`, `\`
17
+ * or a NUL byte. URL parsing resolves `.` and `..` segments first
18
+ * (`/docs/../x` gives `["x"]`), so a dot segment is rejected only when
19
+ * stripping `.md` leaves one (`/docs/...md`, `/docs/%2E%2E.md`). Empty
20
+ * segments from `//` are dropped, not rejected.
17
21
  * - Sets `X-Content-Type-Options: nosniff` on every response.
18
22
  *
19
23
  * @param resolver - Maps a slug to its markdown, or `null` when not found.
@@ -26,8 +30,10 @@ import type { MarkdownResolver, MarkdownRouteOptions } from "./types.js";
26
30
  * // app/[...slug]/route.ts
27
31
  * import { createMarkdownRoute } from "@vllnt/next-llms";
28
32
  *
29
- * export const GET = createMarkdownRoute(async (slug) =>
30
- * getDoc(slug.join("/")),
33
+ * const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
34
+ *
35
+ * export const GET = createMarkdownRoute(
36
+ * (slug) => pages[slug.join("/")] ?? null,
31
37
  * );
32
38
  * ```
33
39
  */
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-route.d.ts","sourceRoot":"","sources":["../src/markdown-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAmCzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,oBAAyB,GACjC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA6BzC"}
1
+ {"version":3,"file":"markdown-route.d.ts","sourceRoot":"","sources":["../src/markdown-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAuCzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,oBAAyB,GACjC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA6BzC"}
@@ -4,13 +4,17 @@ const PLAIN_TEXT_HEADERS = {
4
4
  "X-Content-Type-Options": "nosniff",
5
5
  };
6
6
  /**
7
- * Decode a URL pathname into slug segments, stripping a trailing `.md` from the
8
- * last segment. `/docs/intro.md` → `["docs", "intro"]`; `/` → `[]`.
7
+ * Split a URL pathname into slug segments, dropping empty segments (from `//`),
8
+ * then strip a trailing lowercase `.md` from the last raw segment, then
9
+ * URL-decode each segment. `/docs/intro.md` → `["docs", "intro"]`; `/` → `[]`.
9
10
  *
10
11
  * Returns `null` when the path cannot name a page safely: malformed
11
- * percent-encoding, or a decoded segment that is empty, `.`, `..`, or contains
12
- * `/`, `\` or a NUL byte (so a resolver that maps slugs to files is never
13
- * handed a traversal sequence such as `..%2F..%2Fsecret`).
12
+ * percent-encoding, a segment left empty by stripping `.md` (`/docs/.md`), or a
13
+ * decoded segment that is `.`, `..`, or contains `/`, `\` or a NUL byte (so a
14
+ * resolver that maps slugs to files is never handed a traversal sequence such
15
+ * as `..%2F..%2Fsecret`). `new URL` already resolves `.` and `..` segments,
16
+ * including `%2E` forms, so a dot segment reaches this check only when
17
+ * stripping `.md` leaves one (`/docs/...md`, `/docs/%2E%2E.md`).
14
18
  */
15
19
  function pathnameToSlug(pathname) {
16
20
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
@@ -32,17 +36,21 @@ function pathnameToSlug(pathname) {
32
36
  * Create a Next.js App Router route handler that serves a slug's markdown
33
37
  * content. Mount it at a catch-all route (`app/[...slug]/route.ts`). The handler
34
38
  * is a pure Web-standard `(request) => Promise<Response>` — it imports nothing
35
- * from `next` and runs in any Web runtime.
39
+ * from `next` and uses only Web-standard APIs.
36
40
  *
37
- * - Strips a trailing `.md` from the path (`/docs/intro.md` resolves the slug
38
- * `["docs", "intro"]`).
41
+ * - Strips a trailing lowercase `.md` from the path (`/docs/intro.md`
42
+ * resolves the slug `["docs", "intro"]`).
39
43
  * - Returns `200` with `Content-Type: text/markdown; charset=utf-8` and a
40
44
  * `Cache-Control` header when the resolver returns a string.
41
45
  * - Returns `404` (plain text) when the resolver returns `null` (or any
42
46
  * non-string value, such as `undefined` from a missing map entry).
43
47
  * - Returns `400` (plain text) without calling the resolver when the path has
44
- * malformed percent-encoding or a segment that is empty, `.`, `..`, or
45
- * contains `/`, `\` or a NUL byte.
48
+ * malformed percent-encoding, a segment left empty by stripping `.md`
49
+ * (`/docs/.md`), or a decoded segment that is `.`, `..`, or contains `/`, `\`
50
+ * or a NUL byte. URL parsing resolves `.` and `..` segments first
51
+ * (`/docs/../x` gives `["x"]`), so a dot segment is rejected only when
52
+ * stripping `.md` leaves one (`/docs/...md`, `/docs/%2E%2E.md`). Empty
53
+ * segments from `//` are dropped, not rejected.
46
54
  * - Sets `X-Content-Type-Options: nosniff` on every response.
47
55
  *
48
56
  * @param resolver - Maps a slug to its markdown, or `null` when not found.
@@ -55,8 +63,10 @@ function pathnameToSlug(pathname) {
55
63
  * // app/[...slug]/route.ts
56
64
  * import { createMarkdownRoute } from "@vllnt/next-llms";
57
65
  *
58
- * export const GET = createMarkdownRoute(async (slug) =>
59
- * getDoc(slug.join("/")),
66
+ * const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
67
+ *
68
+ * export const GET = createMarkdownRoute(
69
+ * (slug) => pages[slug.join("/")] ?? null,
60
70
  * );
61
71
  * ```
62
72
  */
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-route.js","sourceRoot":"","sources":["../src/markdown-route.ts"],"names":[],"mappings":"AAEA,MAAM,qBAAqB,GACzB,qEAAqE,CAAC;AAExE,MAAM,kBAAkB,GAAG;IACzB,cAAc,EAAE,2BAA2B;IAC3C,wBAAwB,EAAE,SAAS;CACpC,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7E,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9D,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAA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AAC,CAAC,QAAQ,CAAC,CAAC;QAC3D,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,QAAQ,CAAC,aAAa,EAAE;gBACjC,OAAO,EAAE,kBAAkB;gBAC3B,MAAM,EAAE,GAAG;aACZ,CAAC,CAAC;QACL,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QAErC,OAAO,OAAO,OAAO,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE;gBACpB,OAAO,EAAE;oBACP,eAAe,EAAE,YAAY;oBAC7B,cAAc,EAAE,8BAA8B;oBAC9C,wBAAwB,EAAE,SAAS;iBACpC;gBACD,MAAM,EAAE,GAAG;aACZ,CAAC;YACJ,CAAC,CAAC,IAAI,QAAQ,CAAC,WAAW,EAAE;gBACxB,OAAO,EAAE,kBAAkB;gBAC3B,MAAM,EAAE,GAAG;aACZ,CAAC,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
package/dist/types.d.ts CHANGED
@@ -41,7 +41,9 @@ export type LlmsConfig = {
41
41
  };
42
42
  /**
43
43
  * Maps a route slug to its markdown content, or `null` if there is no page for
44
- * the slug. The slug is the path segments with any trailing `.md` stripped.
44
+ * the slug. The slug is the non-empty path segments, including any route
45
+ * prefix, with a trailing lowercase `.md` removed from the last raw segment,
46
+ * then each segment URL-decoded.
45
47
  */
46
48
  export type MarkdownResolver = (slug: string[]) => string | null | Promise<string | null>;
47
49
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG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,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,MAAM,EAAE,KACX,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
package/docs/API.md CHANGED
@@ -1,16 +1,15 @@
1
1
  # API Reference — @vllnt/next-llms
2
2
 
3
- **Compatibility:** any Web-standard runtime — Next.js App Router (Edge or Node),
4
- Remix, Hono, Deno. Node `>=18`. Zero runtime dependencies.
3
+ **Compatibility:** uses only Web-standard `Request`, `Response`, `URL` and
4
+ `Headers`. Checked with Next.js 16.4.6 App Router route handlers (Node.js and
5
+ Edge runtimes); other runtimes are not tested. Node `>=18`; CI runs the tests on
6
+ Node.js 24 only, so 18 to 23 are not tested. Zero runtime dependencies.
5
7
 
6
- See [release channels](../README.md#installation). `generateLlmsFullText` from
8
+ See [release channels](../README.md#compatibility) and
9
+ [errors and fixes](../README.md#errors-and-fixes). `generateLlmsFullText` from
7
10
  early canary builds is not part of the stable API.
8
11
 
9
- All exports are available from the package root:
10
-
11
- ```ts
12
- import { generateLlmsText, createMarkdownRoute } from "@vllnt/next-llms";
13
- ```
12
+ All exports are available from the package root (`"@vllnt/next-llms"`).
14
13
 
15
14
  ---
16
15
 
@@ -23,7 +22,8 @@ Render an `llms.txt` index manifest from a config object, following the
23
22
  function generateLlmsText(config: LlmsConfig): string;
24
23
  ```
25
24
 
26
- Output layout (blocks joined by a blank line, no trailing newline):
25
+ Output layout (blocks joined by a blank line; no trailing newline is added, but
26
+ a `details` that ends with one keeps it when no section follows it):
27
27
 
28
28
  1. `# {title}` — required H1.
29
29
  2. `> {summary}` — blockquote, when `summary` is set.
@@ -49,13 +49,24 @@ emitted unchanged.
49
49
  | `sections` | `LlmsSection[]?` | Named `## Section` link lists. |
50
50
  | `optional` | `LlmsLink[]?` | Links under the droppable `## Optional` section. |
51
51
 
52
- `LlmsSection` = `{ title: string; links: LlmsLink[] }`. `LlmsLink` =
53
- `{ title: string; url: string; notes?: string }`.
52
+ ### `LlmsSection`
53
+
54
+ `{ title: string; links: LlmsLink[] }` — one `## {title}` block and its links.
55
+ `title` is required; a section with an empty `links` array renders only its
56
+ heading.
57
+
58
+ ### `LlmsLink`
59
+
60
+ `{ title: string; url: string; notes?: string }` — one `- [title](url): notes`
61
+ line. `title` and `url` are required; `: notes` is left out when `notes` is
62
+ empty.
54
63
 
55
64
  ### Example
56
65
 
57
66
  ```ts
58
- generateLlmsText({
67
+ import { generateLlmsText } from "@vllnt/next-llms";
68
+
69
+ export const text = generateLlmsText({
59
70
  title: "Acme Docs",
60
71
  summary: "Everything an agent needs to use Acme.",
61
72
  sections: [
@@ -83,35 +94,54 @@ function createMarkdownRoute(
83
94
  ): (request: Request) => Promise<Response>;
84
95
  ```
85
96
 
86
- `MarkdownResolver` =
97
+ ### `MarkdownResolver`
98
+
87
99
  `(slug: string[]) => string | null | Promise<string | null>`. The slug is the
88
- path segments, URL-decoded, with any trailing `.md` removed.
100
+ full request path's non-empty segments: a trailing lowercase `.md` is removed
101
+ from the last raw segment, then each segment is URL-decoded (`/docs/intro%2Emd`
102
+ gives `["docs", "intro.md"]`). It includes any route prefix (`/md/docs/intro.md`
103
+ gives `["md", "docs", "intro"]`). Return a string for content or `null` for not
104
+ found.
89
105
 
90
- `MarkdownRouteOptions` = `{ cacheControl?: string }`.
106
+ ### `MarkdownRouteOptions`
107
+
108
+ `{ cacheControl?: string }` — the `Cache-Control` value for `200` responses.
109
+ `cacheControl: ""` sends an empty `Cache-Control` header; it does not fall back
110
+ to the default.
91
111
 
92
112
  ### Behavior
93
113
 
94
- | Request | Resolver returns | Response |
95
- | ---------------------------- | ---------------- | -------------------------------------------------------------------- |
96
- | `/docs/intro.md` | `"# Intro…"` | `200`, `Content-Type: text/markdown; charset=utf-8`, `Cache-Control` |
97
- | `/docs/intro.md` | `""` | `200` with an empty body (empty string is content, not absence) |
98
- | `/missing.md` | `null` | `404`, `Content-Type: text/plain; charset=utf-8`, body `Not Found` |
99
- | `/missing.md` | non-string | `404`, same as `null` |
100
- | `/..%2Fsecret`, `/a%00b` | not called | `400`, `text/plain`, body `Bad Request` |
101
- | `/docs/getting%20started.md` | — | resolver receives `["docs", "getting started"]` |
102
- | `/` | — | resolver receives `[]` |
114
+ | Request | Resolver returns | Response |
115
+ | ---------------------------- | ---------------- | ------------------------------------------------------------------------------------------- |
116
+ | `/docs/intro.md` | `"# Intro…"` | `200`, `Content-Type: text/markdown; charset=utf-8`, `Cache-Control` |
117
+ | `/docs/intro.md` | `""` | `200` with an empty body (empty string is content, not absence) |
118
+ | `/missing.md` | `null` | `404`, `Content-Type: text/plain; charset=utf-8`, body `Not Found` |
119
+ | `/missing.md` | non-string | `404`, same as `null` |
120
+ | `/..%2Fsecret`, `/a%00b` | not called | `400`, `text/plain`, body `Bad Request` |
121
+ | `/docs/getting%20started.md` | — | resolver receives `["docs", "getting started"]` |
122
+ | `/` | — | resolver receives `[]` (needs `app/[[...slug]]` in Next.js; `[...slug]` does not match `/`) |
103
123
 
104
124
  A request is rejected with `400` (the resolver is not called) when the path has
105
- malformed percent-encoding or a decoded segment that is empty, `.`, `..`, or
106
- contains `/`, `\` or a NUL byte. Every response carries
125
+ malformed percent-encoding, a segment left empty by stripping `.md` (`/.md`,
126
+ `/docs/.md`), a segment that is `.` or `..` after stripping `.md` and decoding
127
+ (`/docs/...md`), or a decoded segment that contains `/`, `\` or a NUL byte. URL
128
+ parsing resolves plain `.` and `..` segments, including `%2E` forms, before the
129
+ handler runs (`/docs/../x` gives `["x"]`), so the resolver never receives them.
130
+ Empty segments from `//` are dropped, not rejected (`/docs//intro.md` gives
131
+ `["docs", "intro"]`; in Next.js the request first gets a `308` redirect to
132
+ `/docs/intro.md`). In Next.js, malformed percent-encoding (such as
133
+ `/docs/%E0.md`) gets Next's own `500` before the handler runs, so only the
134
+ segment checks are seen there. Every response carries
107
135
  `X-Content-Type-Options: nosniff`. An invalid `cacheControl` value throws a
108
136
  `TypeError` when the handler is created.
109
137
 
110
138
  Default `Cache-Control`:
111
139
  `public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800` — override
112
140
  with `options.cacheControl`. For private or personalized responses, explicitly
113
- use `{ cacheControl: "private, no-store" }` and authorize access in the
114
- resolver. The public default is not suitable for authenticated content.
141
+ use `{ cacheControl: "private, no-store" }`, and check the request in your own
142
+ `GET` before calling the handler: the resolver receives only the slug (see
143
+ [Common tasks](../README.md#common-tasks)). The public default is not suitable
144
+ for authenticated content.
115
145
 
116
146
  ### Example
117
147
 
@@ -119,8 +149,10 @@ resolver. The public default is not suitable for authenticated content.
119
149
  // app/[...slug]/route.ts
120
150
  import { createMarkdownRoute } from "@vllnt/next-llms";
121
151
 
152
+ const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
153
+
122
154
  export const GET = createMarkdownRoute(
123
- async (slug) => (await getDoc(slug.join("/")))?.markdown ?? null,
155
+ (slug) => pages[slug.join("/")] ?? null,
124
156
  { cacheControl: "public, max-age=60" },
125
157
  );
126
158
  ```
package/llms.txt CHANGED
@@ -1,36 +1,63 @@
1
1
  # @vllnt/next-llms
2
2
 
3
- > AI discoverability for Next.js sites — generate llms.txt manifests and serve
4
- > any page as raw markdown.
3
+ > Generate an llms.txt file and serve pages as Markdown from Next.js App Router
4
+ > route handlers, using Web-standard Request and Response and no dependencies.
5
5
 
6
- `@vllnt/next-llms` is a publishable, zero-dependency TypeScript package for
7
- Next.js (App Router) and any Web-standard runtime. It exposes two functions.
6
+ `@vllnt/next-llms` is a TypeScript ESM package with two functions.
8
7
  `generateLlmsText(config)` returns an `llms.txt` index string in the llmstxt.org
9
8
  shape — an `#` title, a `>` blockquote, optional free prose, `## Section` link
10
- lists (`- [title](https://github.com/vllnt/next-llms/blob/main/url): notes`), and a droppable `## Optional` section.
9
+ lists (`- [title](url): notes`), and a droppable `## Optional` section.
11
10
  `createMarkdownRoute(resolver, options?)` returns a Web-standard
12
- `(request) => Promise<Response>` route handler: it URL-decodes the pathname,
13
- strips a trailing `.md`, calls the resolver with the slug, and returns `200`
14
- `text/markdown` with a `Cache-Control` header when the resolver returns a string
15
- (an empty string is content), or `404` `text/plain` when it returns `null`. The
16
- handler imports nothing from `next`; `null` is the explicit not-found sentinel.
17
-
18
- The stable API is the two functions above; the older `generateLlmsFullText`
19
- API from early canary builds is not included. Install `@vllnt/next-llms`;
20
- prereleases are on the `canary` tag. Node.js >=18; no peer dependencies.
21
- Successful responses use public caching by default. Authorize in the resolver and
22
- set `cacheControl: "private, no-store"` for private/personalized content.
11
+ `(request) => Promise<Response>` route handler: it drops empty path segments,
12
+ strips a trailing lowercase `.md` from the last segment, then URL-decodes each
13
+ segment, calls the resolver with the slug, and returns `200` `text/markdown`
14
+ with a `Cache-Control` header when the resolver returns a string (an empty
15
+ string is content), or `404` `text/plain` when it returns `null` or any other
16
+ non-string. A path with malformed percent-encoding, a segment that is empty,
17
+ `.` or `..` after stripping `.md` and decoding (such as `/.md` or `/...md`), or
18
+ a decoded segment that contains `/`, `\` or NUL gets `400` without calling the
19
+ resolver (URL parsing already resolves plain `.` and `..` segments, so
20
+ `/docs/../x` gives `["x"]`); in Next.js, malformed percent-encoding gets Next's
21
+ own `500` before the handler runs. In Next.js, `HEAD` is answered from `GET`,
22
+ `OPTIONS` gets `204` and other methods get `405`. The handler imports nothing
23
+ from `next`. Node.js >=18 (CI tests only Node.js 24); no peer or runtime
24
+ dependencies.
25
+ Successful responses use public caching by default; pass
26
+ `cacheControl: "private, no-store"` for private content and check the request in
27
+ your own `GET`, because the resolver only receives the slug.
28
+
29
+ When to use:
30
+
31
+ - Use it when your Next.js site should serve an `/llms.txt` link index.
32
+ - Use it when you have Markdown for your pages and want it at `.md` URLs.
33
+ - Do not use it to build the link list from your routes; build it in your code.
34
+ - Do not use it to convert HTML to Markdown; use a converter such as `turndown`.
35
+ - Do not use it for `llms-full.txt`; concatenate your pages in your own route.
36
+
37
+ For coding agents: the docs ship in `node_modules/@vllnt/next-llms/` next to
38
+ the TypeScript source in `src/` and match the installed version. This file
39
+ describes the package itself; it is not output of `generateLlmsText`.
23
40
 
24
41
  ## Docs
25
42
 
26
- - [README](https://github.com/vllnt/next-llms/blob/main/README.md): Overview, installation, usage examples
27
- - [API Reference](https://github.com/vllnt/next-llms/blob/main/docs/API.md): Function signatures, config types, response behavior
28
- - [Changelog](https://github.com/vllnt/next-llms/blob/main/CHANGELOG.md): Version history and release notes
43
+ - [README](./README.md): Install, quick start, common tasks, limits and gotchas, compatibility
44
+ - [API Reference](./docs/API.md): Every export, its types and the route's response behavior
45
+ - [Errors and fixes](./README.md#errors-and-fixes): Every error the package raises and every error response, its cause and the fix
46
+ - [Changelog](./CHANGELOG.md): Version history and release notes
29
47
  - [Contributing](https://github.com/vllnt/next-llms/blob/main/CONTRIBUTING.md): Development setup, validation commands, release workflow
30
48
 
31
49
  ## Optional
32
50
 
33
- - [AGENTS](https://github.com/vllnt/next-llms/blob/main/AGENTS.md): Canonical agent instructions for this repository
51
+ - [AGENTS](https://github.com/vllnt/next-llms/blob/main/AGENTS.md): Agent instructions for contributors to this repository
34
52
  - [Security Policy](https://github.com/vllnt/next-llms/blob/main/SECURITY.md): Vulnerability reporting policy
35
53
  - [Code of Conduct](https://github.com/vllnt/next-llms/blob/main/CODE_OF_CONDUCT.md): Community participation guidelines
36
- - [License](https://github.com/vllnt/next-llms/blob/main/LICENSE): MIT license
54
+ - [License](./LICENSE): MIT license
55
+
56
+ ## Ecosystem
57
+
58
+ - [Package page](https://oss.vllnt.com/packages/next-llms)
59
+ - [Release feed](https://oss.vllnt.com/packages/next-llms/rss.xml)
60
+ - [All @vllnt packages](https://oss.vllnt.com/llms.txt)
61
+ - [Search vllnt packages and docs](https://index.vllnt.com)
62
+ - [vllnt](https://vllnt.com/llms.txt)
63
+ - [Author](https://bntvllnt.com)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@vllnt/next-llms",
3
- "version": "0.1.0",
4
- "description": "AI discoverability for Next.js sites — generate an llms.txt manifest and serve any page as raw markdown",
3
+ "version": "0.1.1-canary.253bc5f",
4
+ "description": "Generate an llms.txt file and serve pages as Markdown from Next.js App Router route handlers, using Web-standard Request and Response and no dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "packageManager": "pnpm@10.34.8",
7
+ "packageManager": "pnpm@12.22.0",
8
8
  "files": [
9
9
  "dist",
10
10
  "src",
@@ -34,21 +34,22 @@
34
34
  "test": "vitest run --passWithNoTests",
35
35
  "test:watch": "vitest --typecheck --clearScreen false",
36
36
  "test:coverage": "vitest run --coverage --coverage.reporter=text",
37
+ "test:package": "bash scripts/test-package.sh",
37
38
  "preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck",
38
39
  "check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\""
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/node": "^24.19.2",
42
43
  "@typescript/native": "npm:typescript@7.0.2",
43
- "@vitest/coverage-v8": "^5.0.5",
44
- "@vllnt/eslint-config": "2.0.0",
45
- "@vllnt/typescript": "2.0.0",
46
- "eslint": "^9.0.0",
47
- "prettier": "^3.9.10",
44
+ "@vitest/coverage-v8": "^5.1.1",
45
+ "@vllnt/eslint-config": "2.1.0",
46
+ "@vllnt/typescript": "3.0.0",
47
+ "eslint": "^10.15.0",
48
+ "prettier": "^3.10.1",
48
49
  "typescript": "npm:@typescript/typescript6@^6.0.2",
49
- "vitest": "^5.0.5"
50
+ "vitest": "^5.1.1"
50
51
  },
51
- "homepage": "https://github.com/vllnt/next-llms#readme",
52
+ "homepage": "https://oss.vllnt.com/packages/next-llms",
52
53
  "bugs": {
53
54
  "url": "https://github.com/vllnt/next-llms/issues"
54
55
  },
@@ -72,28 +73,15 @@
72
73
  },
73
74
  "sideEffects": false,
74
75
  "keywords": [
75
- "nextjs",
76
- "next",
77
- "llms-txt",
78
76
  "llms.txt",
79
- "ai",
80
- "llm",
81
- "seo",
77
+ "llms-txt",
78
+ "nextjs",
82
79
  "app-router",
80
+ "route-handler",
83
81
  "markdown",
84
- "discoverability"
85
- ],
86
- "pnpm": {
87
- "minimumReleaseAge": 10080,
88
- "minimumReleaseAgeExclude": [
89
- "@vllnt/*"
90
- ],
91
- "ignoredBuiltDependencies": [
92
- "esbuild"
93
- ],
94
- "overrides": {
95
- "deepmerge-ts@<8.0.0": "8.0.2",
96
- "handlebars@<4.7.10": "4.7.10"
97
- }
98
- }
82
+ "llm",
83
+ "ai-agents",
84
+ "typescript",
85
+ "edge-runtime"
86
+ ]
99
87
  }
package/src/index.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Generate an `llms.txt` file and serve pages as Markdown from Next.js App
3
+ * Router route handlers.
4
+ *
5
+ * @packageDocumentation
6
+ * @see https://oss.vllnt.com/packages/next-llms
7
+ */
1
8
  export { generateLlmsText } from "./llms-text.js";
2
9
  export { createMarkdownRoute } from "./markdown-route.js";
3
10
  export type {
package/src/llms-text.ts CHANGED
@@ -57,7 +57,9 @@ function renderSection(section: LlmsSection): string {
57
57
  * prose, `## {section}` link lists, and a droppable `## Optional` section.
58
58
  *
59
59
  * @param config - The manifest content.
60
- * @returns The `llms.txt` file contents (no trailing newline).
60
+ * @returns The `llms.txt` file contents. No trailing newline is added; a
61
+ * `details` value that ends with one keeps it when no section (from `sections`
62
+ * or `optional`) follows it.
61
63
  * @throws {TypeError} When a title or link URL is blank, or a URL uses a
62
64
  * `javascript:`, `data:` or `vbscript:` scheme. Line breaks inside titles,
63
65
  * summaries and notes are collapsed to spaces, `[`, `]` and `\` in link titles
@@ -9,13 +9,17 @@ const PLAIN_TEXT_HEADERS = {
9
9
  };
10
10
 
11
11
  /**
12
- * Decode a URL pathname into slug segments, stripping a trailing `.md` from the
13
- * last segment. `/docs/intro.md` → `["docs", "intro"]`; `/` → `[]`.
12
+ * Split a URL pathname into slug segments, dropping empty segments (from `//`),
13
+ * then strip a trailing lowercase `.md` from the last raw segment, then
14
+ * URL-decode each segment. `/docs/intro.md` → `["docs", "intro"]`; `/` → `[]`.
14
15
  *
15
16
  * Returns `null` when the path cannot name a page safely: malformed
16
- * percent-encoding, or a decoded segment that is empty, `.`, `..`, or contains
17
- * `/`, `\` or a NUL byte (so a resolver that maps slugs to files is never
18
- * handed a traversal sequence such as `..%2F..%2Fsecret`).
17
+ * percent-encoding, a segment left empty by stripping `.md` (`/docs/.md`), or a
18
+ * decoded segment that is `.`, `..`, or contains `/`, `\` or a NUL byte (so a
19
+ * resolver that maps slugs to files is never handed a traversal sequence such
20
+ * as `..%2F..%2Fsecret`). `new URL` already resolves `.` and `..` segments,
21
+ * including `%2E` forms, so a dot segment reaches this check only when
22
+ * stripping `.md` leaves one (`/docs/...md`, `/docs/%2E%2E.md`).
19
23
  */
20
24
  function pathnameToSlug(pathname: string): string[] | null {
21
25
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
@@ -37,17 +41,21 @@ function pathnameToSlug(pathname: string): string[] | null {
37
41
  * Create a Next.js App Router route handler that serves a slug's markdown
38
42
  * content. Mount it at a catch-all route (`app/[...slug]/route.ts`). The handler
39
43
  * is a pure Web-standard `(request) => Promise<Response>` — it imports nothing
40
- * from `next` and runs in any Web runtime.
44
+ * from `next` and uses only Web-standard APIs.
41
45
  *
42
- * - Strips a trailing `.md` from the path (`/docs/intro.md` resolves the slug
43
- * `["docs", "intro"]`).
46
+ * - Strips a trailing lowercase `.md` from the path (`/docs/intro.md`
47
+ * resolves the slug `["docs", "intro"]`).
44
48
  * - Returns `200` with `Content-Type: text/markdown; charset=utf-8` and a
45
49
  * `Cache-Control` header when the resolver returns a string.
46
50
  * - Returns `404` (plain text) when the resolver returns `null` (or any
47
51
  * non-string value, such as `undefined` from a missing map entry).
48
52
  * - Returns `400` (plain text) without calling the resolver when the path has
49
- * malformed percent-encoding or a segment that is empty, `.`, `..`, or
50
- * contains `/`, `\` or a NUL byte.
53
+ * malformed percent-encoding, a segment left empty by stripping `.md`
54
+ * (`/docs/.md`), or a decoded segment that is `.`, `..`, or contains `/`, `\`
55
+ * or a NUL byte. URL parsing resolves `.` and `..` segments first
56
+ * (`/docs/../x` gives `["x"]`), so a dot segment is rejected only when
57
+ * stripping `.md` leaves one (`/docs/...md`, `/docs/%2E%2E.md`). Empty
58
+ * segments from `//` are dropped, not rejected.
51
59
  * - Sets `X-Content-Type-Options: nosniff` on every response.
52
60
  *
53
61
  * @param resolver - Maps a slug to its markdown, or `null` when not found.
@@ -60,8 +68,10 @@ function pathnameToSlug(pathname: string): string[] | null {
60
68
  * // app/[...slug]/route.ts
61
69
  * import { createMarkdownRoute } from "@vllnt/next-llms";
62
70
  *
63
- * export const GET = createMarkdownRoute(async (slug) =>
64
- * getDoc(slug.join("/")),
71
+ * const pages: Record<string, string> = { "docs/intro": "# Intro\n\nHello." };
72
+ *
73
+ * export const GET = createMarkdownRoute(
74
+ * (slug) => pages[slug.join("/")] ?? null,
65
75
  * );
66
76
  * ```
67
77
  */
package/src/types.ts CHANGED
@@ -44,7 +44,9 @@ export type LlmsConfig = {
44
44
 
45
45
  /**
46
46
  * Maps a route slug to its markdown content, or `null` if there is no page for
47
- * the slug. The slug is the path segments with any trailing `.md` stripped.
47
+ * the slug. The slug is the non-empty path segments, including any route
48
+ * prefix, with a trailing lowercase `.md` removed from the last raw segment,
49
+ * then each segment URL-decoded.
48
50
  */
49
51
  export type MarkdownResolver = (
50
52
  slug: string[],