Skip to content

Commit 5d9b03a

Browse files
Add llms-txt generator module and integrate it
1 parent c0f0f3c commit 5d9b03a

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/generators/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import legacyJsonAll from './legacy-json-all/index.mjs';
99
import addonVerify from './addon-verify/index.mjs';
1010
import apiLinks from './api-links/index.mjs';
1111
import oramaDb from './orama-db/index.mjs';
12+
import llmsTxt from './llms-txt/index.mjs';
1213

1314
export default {
1415
'json-simple': jsonSimple,
@@ -20,4 +21,5 @@ export default {
2021
'addon-verify': addonVerify,
2122
'api-links': apiLinks,
2223
'orama-db': oramaDb,
24+
'llms-txt': llmsTxt,
2325
};

src/generators/llms-txt/index.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
import { writeFile } from 'node:fs/promises';
4+
import { join } from 'node:path';
5+
6+
/**
7+
* This generator generates the `llms.txt` file that provides an AI-readable index of all the documentation.
8+
*
9+
* @typedef {Array<ApiDocMetadataEntry>} Input
10+
*
11+
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
12+
*/
13+
export default {
14+
name: 'llms-txt',
15+
16+
version: '1.0.0',
17+
18+
description: 'Generates the `llms.txt` file that provides an AI-readable index of all the documentation.',
19+
20+
dependsOn: 'ast',
21+
22+
/**
23+
* Generates the `llms.txt` file.
24+
*
25+
* @param {Input} input
26+
* @param {Partial<GeneratorOptions>} options
27+
*/
28+
async generate(input, { output }) {
29+
const projectName = 'Node.js Documentation';
30+
const projectSummary = 'Comprehensive documentation for Node.js, including API references, guides, and tutorials.';
31+
const projectDetails = 'This documentation provides detailed information about Node.js, its APIs, and usage examples. It is designed to help developers understand and use Node.js effectively.';
32+
33+
const fileList = input.map(entry => {
34+
const url = `https://nodejs.org/docs/latest-v${entry.api}.html#${entry.slug}`;
35+
return `- [${entry.heading.data.text}](${url})`;
36+
}).join('\n');
37+
38+
const llmsTxtContent = `
39+
# ${projectName}
40+
41+
## Summary
42+
${projectSummary}
43+
44+
## Details
45+
${projectDetails}
46+
47+
## Files
48+
${fileList}
49+
`;
50+
51+
if (output) {
52+
await writeFile(join(output, 'llms.txt'), llmsTxtContent);
53+
}
54+
55+
return llmsTxtContent;
56+
},
57+
};

0 commit comments

Comments
 (0)