Skip to content

Commit 3b2d6f9

Browse files
committed
refactor(react): move llms-full.txt into a llms-full-txt generator
llms-full.txt shares no data with llms.txt, so it gets its own generator, like legacy-html-all. writeMarkdown is dropped: the pages' Markdown is the input, which a build can copy as is. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 64217c9 commit 3b2d6f9

19 files changed

Lines changed: 117 additions & 49 deletions

File tree

‎.changeset/llms-full.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2+
'@doc-kit/core': minor
23
'@doc-kit/generator-react': minor
34
---
45

5-
Add the `writeMarkdown` and `writeFull` options to the `llms-txt` generator, writing the Markdown of every page at the URLs `llms.txt` links, and a `llms-full.txt` file holding them all.
6+
Add the `llms-full-txt` generator, writing a `llms-full.txt` file holding the Markdown of every page, each preceded by its URL.

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ Options:
7272
(json, json-all, json-simple, legacy-html,
7373
legacy-html-all, man-page, legacy-json,
7474
legacy-json-all, addon-verify, api-links,
75-
orama-db, llms-txt, sitemap, html,
76-
section-pages) or an import specifier for a
77-
custom generator
75+
orama-db, llms-txt, llms-full-txt, sitemap,
76+
html, section-pages) or an import specifier
77+
for a custom generator
7878
--ignore <patterns...> Ignore file patterns (glob)
7979
-o, --output <directory> The output directory
8080
-p, --threads <number> Number of threads to use (minimum: 1)

‎docs/generators.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ npx @doc-kit/cli generate -t html -t orama-db -t sitemap -i "docs/**/*.md" -o ou
1515
| [`html`](./generators/html.md) | The modern documentation site: server-rendered, hydrated, themeable. |
1616
| [`orama-db`](./generators/orama-db.md) | The search index behind the `html` site's search box. |
1717
| [`llms-txt`](./generators/llms-txt.md) | An [`llms.txt`](https://llmstxt.org/) index for language models. |
18+
| [`llms-full-txt`](./generators/llms-full-txt.md) | Every page's Markdown in one `llms-full.txt`, for language models. |
1819
| [`sitemap`](./generators/sitemap.md) | A `sitemap.xml` for search engines. |
1920
| [`section-pages`](./generators/section-pages.md) | The `html` site and sitemap, plus one page per section of a module. |
2021

‎packages/core/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ debugging-only `json-simple`); the rest come from companion packages:
1515

1616
| Package | Generators |
1717
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
18-
| [`@doc-kit/generator-react`](https://www.npmjs.com/package/@doc-kit/generator-react) | `html` (the modern site), `orama-db`, `llms-txt`, `sitemap` |
18+
| [`@doc-kit/generator-react`](https://www.npmjs.com/package/@doc-kit/generator-react) | `html` (the modern site), `orama-db`, `llms-txt`, `llms-full-txt`, `sitemap` |
1919
| [`@node-core/doc-kit-legacy`](https://www.npmjs.com/package/@node-core/doc-kit-legacy) | `legacy-html`, `legacy-html-all`, `legacy-json`, `legacy-json-all` (Node.js-specific) |
2020
| [`@node-core/doc-kit`](https://www.npmjs.com/package/@node-core/doc-kit) | `man-page`, `api-links`, `addon-verify` (Node.js-specific) |
2121

‎packages/core/src/generators/index.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const publicGenerators = {
2222
'api-links': '@node-core/doc-kit/api-links',
2323
'orama-db': '@doc-kit/generator-react/orama-db',
2424
'llms-txt': '@doc-kit/generator-react/llms-txt',
25+
'llms-full-txt': '@doc-kit/generator-react/llms-full-txt',
2526
sitemap: '@doc-kit/generator-react/sitemap',
2627
html: '@doc-kit/generator-react/html',
2728
'section-pages': '@doc-kit/generator-react/section-pages',

‎packages/react/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ npm install --save-dev @doc-kit/core @doc-kit/generator-react
1717
| `html` | The full documentation site — server-rendered pages hydrated with Preact, bundled with Vite. |
1818
| `orama-db` | An [Orama](https://orama.com) search index, consumed by the `html` site's search box. |
1919
| `llms-txt` | An [`llms.txt`](https://llmstxt.org/) index for Large Language Models. |
20+
| `llms-full-txt` | Every page's Markdown in one `llms-full.txt`, for Large Language Models. |
2021
| `sitemap` | A `sitemap.xml` for search engines. |
2122
| `section-pages` | The `html` site and sitemap, plus one page per section of every module. |
2223

‎packages/react/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@doc-kit/generator-react",
33
"type": "module",
44
"version": "0.4.0",
5-
"description": "React/JSX-based generators for @doc-kit/core: html, jsx-ast, llms-txt, sitemap, and orama-db",
5+
"description": "React/JSX-based generators for @doc-kit/core: html, jsx-ast, llms-txt, llms-full-txt, sitemap, and orama-db",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/nodejs/doc-kit.git",
@@ -15,6 +15,7 @@
1515
"./html/ui/*": "./src/html/ui/*",
1616
"./html/bundlers/vite": "./src/html/bundlers/vite.mjs",
1717
"./jsx-ast": "./src/jsx-ast/index.mjs",
18+
"./llms-full-txt": "./src/llms-full-txt/index.mjs",
1819
"./llms-txt": "./src/llms-txt/index.mjs",
1920
"./orama-db": "./src/orama-db/index.mjs",
2021
"./sitemap": "./src/sitemap/index.mjs",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `llms-full-txt` Generator
2+
3+
The `llms-full-txt` generator creates a `llms-full.txt` file holding the Markdown of every page, each preceded by its URL, so Large Language Models (LLMs) can read the whole documentation in one request. Pages are rebuilt from their metadata entries, leaving out the ones other generators create.
4+
5+
## Configuring
6+
7+
- `output` {string} The directory where `llms-full.txt` will be written.
8+
- `pageURL` {string} URL template for the URL preceding each page.
9+
**Default:** `'{baseURL}{path}.md'`.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs';
5+
import { u } from 'unist-builder';
6+
7+
import { generate } from '../generate.mjs';
8+
9+
const config = await setConfig({ target: ['llms-full-txt'] });
10+
11+
const entry = (path, text) => ({
12+
path,
13+
content: u('root', [u('paragraph', [u('text', text)])]),
14+
});
15+
16+
describe('llms-full-txt', () => {
17+
it('precedes the Markdown of every page with its URL', async () => {
18+
config['llms-full-txt'].baseURL = 'https://example.com';
19+
config['llms-full-txt'].output = undefined;
20+
21+
const full = await generate([entry('/a', 'First.'), entry('/b', 'Other.')]);
22+
23+
assert.equal(
24+
full,
25+
'---\nurl: https://example.com/a.md\n---\nFirst.\n\n' +
26+
'---\nurl: https://example.com/b.md\n---\nOther.\n'
27+
);
28+
});
29+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
import { join } from 'node:path';
4+
5+
import getConfig from '@doc-kit/core/utils/configuration/index.mjs';
6+
import { populate } from '@doc-kit/core/utils/configuration/templates.mjs';
7+
import { writeFile } from '@doc-kit/core/utils/file.mjs';
8+
9+
import { buildPages } from './utils/buildPages.mjs';
10+
11+
/**
12+
* Generates a llms-full.txt file
13+
*
14+
* @type {import('./types').Generator['generate']}
15+
*/
16+
export async function generate(input) {
17+
const config = getConfig('llms-full-txt');
18+
19+
const full = buildPages(input)
20+
.map(
21+
({ path, markdown }) =>
22+
`---\nurl: ${populate(config.pageURL, { ...config, path })}\n---\n${markdown}`
23+
)
24+
.join('\n');
25+
26+
if (config.output) {
27+
await writeFile(join(config.output, 'llms-full.txt'), full);
28+
}
29+
30+
return full;
31+
}

0 commit comments

Comments
 (0)