Skip to content

Commit 71aeb87

Browse files
committed
add llm
1 parent cc003c6 commit 71aeb87

File tree

5 files changed

+155
-4
lines changed

5 files changed

+155
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Generated files
88
.docusaurus
99
.cache-loader
10+
static/llm-context.md
1011

1112
# Misc
1213
.DS_Store

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,28 @@ This command starts a local development server and opens up a browser window. Mo
2727
$ npm run build
2828
```
2929

30-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
30+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
31+
32+
### Generate LLM Context
33+
34+
```
35+
$ npm run generate-llm-context
36+
```
37+
38+
This command generates a single `llm-context.md` file in the `static/` folder containing all documentation merged together, optimized for use with AI assistants (ChatGPT, Claude, etc.).
39+
40+
**Features:**
41+
- Concatenates all markdown files from the `docs/` directory
42+
- Maintains proper document order (sorted by filename)
43+
- Includes table of contents
44+
- Adds metadata (generation time, file count, statistics)
45+
- ~16,000 tokens - fits comfortably in most LLM context windows
46+
- **Accessible from website navbar** (after build/deploy)
47+
48+
**Use cases:**
49+
- Provide complete documentation context to AI assistants
50+
- Training or fine-tuning language models
51+
- Quick reference for AI-powered development tools
52+
- Documentation analysis and processing
53+
54+
The generated file is automatically excluded from git (added to `.gitignore`). It's also automatically generated before each build and deployment, and is accessible from the website's navigation menu.

docusaurus.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ const config = {
5353
position: "left",
5454
label: "Docs",
5555
},
56+
{
57+
href: "/llm-context.md",
58+
label: "LLM Context",
59+
position: "left",
60+
target: "_blank",
61+
},
5662
{
5763
href: "https://github.com/adaptivestone/framework-documenation",
5864
label: "GitHub (docs)",

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"scripts": {
66
"docusaurus": "docusaurus",
77
"start": "docusaurus start",
8-
"build": "docusaurus build",
8+
"build": "npm run generate-llm-context && docusaurus build",
99
"swizzle": "docusaurus swizzle",
10-
"deploy": "docusaurus deploy",
10+
"deploy": "npm run generate-llm-context && docusaurus deploy",
1111
"clear": "docusaurus clear",
1212
"serve": "docusaurus serve",
1313
"write-translations": "docusaurus write-translations",
14-
"write-heading-ids": "docusaurus write-heading-ids"
14+
"write-heading-ids": "docusaurus write-heading-ids",
15+
"generate-llm-context": "node scripts/generate-llm-context.js"
1516
},
1617
"dependencies": {
1718
"@docusaurus/core": "^3.0.0",

scripts/generate-llm-context.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
const fs = require('node:fs');
2+
const path = require('node:path');
3+
4+
// Configuration
5+
const DOCS_DIR = path.join(__dirname, '../docs');
6+
const OUTPUT_FILE = path.join(__dirname, '../static/llm-context.md');
7+
8+
/**
9+
* Recursively get all markdown files from a directory
10+
* @param {string} dir - Directory to search
11+
* @param {string} baseDir - Base directory for relative paths
12+
* @returns {Array<{path: string, relativePath: string}>}
13+
*/
14+
function getAllMarkdownFiles(dir, baseDir = dir) {
15+
let results = [];
16+
const items = fs.readdirSync(dir, { withFileTypes: true });
17+
18+
for (const item of items) {
19+
const fullPath = path.join(dir, item.name);
20+
21+
if (item.isDirectory()) {
22+
// Recursively search subdirectories
23+
results = results.concat(getAllMarkdownFiles(fullPath, baseDir));
24+
} else if (item.isFile() && item.name.endsWith('.md')) {
25+
const relativePath = path.relative(baseDir, fullPath);
26+
results.push({ path: fullPath, relativePath });
27+
}
28+
}
29+
30+
return results;
31+
}
32+
33+
/**
34+
* Sort files in a logical order (numerical prefix first, then alphabetically)
35+
*/
36+
function sortFiles(files) {
37+
return files.sort((a, b) => {
38+
// Sort by relative path for proper hierarchy
39+
const pathA = a.relativePath.toLowerCase();
40+
const pathB = b.relativePath.toLowerCase();
41+
42+
return pathA.localeCompare(pathB, undefined, { numeric: true });
43+
});
44+
}
45+
46+
/**
47+
* Generate the LLM context file
48+
*/
49+
function generateLLMContext() {
50+
console.log('🔍 Scanning documentation files...');
51+
52+
// Get all markdown files
53+
const markdownFiles = getAllMarkdownFiles(DOCS_DIR);
54+
const sortedFiles = sortFiles(markdownFiles);
55+
56+
console.log(`📄 Found ${sortedFiles.length} markdown files`);
57+
58+
// Create output content
59+
let output = '';
60+
61+
// Add header
62+
output += '# Adaptivestone Framework - Complete Documentation\n\n';
63+
output += '> This file is auto-generated from the Docusaurus documentation.\n';
64+
output += `> Generated on: ${new Date().toISOString()}\n`;
65+
output += `> Total documents: ${sortedFiles.length}\n\n`;
66+
output += '---\n\n';
67+
68+
// Add table of contents
69+
output += '## Table of Contents\n\n';
70+
sortedFiles.forEach((file, index) => {
71+
const title = file.relativePath.replace(/\.md$/, '').replace(/\//g, ' / ');
72+
output += `${index + 1}. ${title}\n`;
73+
});
74+
output += '\n---\n\n';
75+
76+
// Concatenate all files
77+
sortedFiles.forEach((file, index) => {
78+
console.log(` ├─ Processing: ${file.relativePath}`);
79+
80+
// Add section header
81+
const sectionTitle = file.relativePath.replace(/\.md$/, '').replace(/\//g, ' > ');
82+
output += `\n\n# Document ${index + 1}: ${sectionTitle}\n\n`;
83+
output += `<!-- Source: ${file.relativePath} -->\n\n`;
84+
85+
// Read and add file content
86+
const content = fs.readFileSync(file.path, 'utf8');
87+
output += content;
88+
89+
// Add separator between documents
90+
output += '\n\n---\n';
91+
});
92+
93+
// Add footer
94+
output += '\n\n<!-- End of Documentation -->\n';
95+
96+
// Write output file
97+
fs.writeFileSync(OUTPUT_FILE, output, 'utf8');
98+
99+
// Calculate statistics
100+
const stats = fs.statSync(OUTPUT_FILE);
101+
const words = output.split(/\s+/).length;
102+
const estimatedTokens = Math.round(words * 1.3); // Rough estimate: 1 word ≈ 1.3 tokens
103+
104+
console.log('\n✅ LLM context file generated successfully!');
105+
console.log(`\n📊 Statistics:`);
106+
console.log(` - Output file: ${path.relative(process.cwd(), OUTPUT_FILE)}`);
107+
console.log(` - File size: ${(stats.size / 1024).toFixed(2)} KB`);
108+
console.log(` - Word count: ${words.toLocaleString()}`);
109+
console.log(` - Estimated tokens: ${estimatedTokens.toLocaleString()}`);
110+
console.log(`\n💡 You can now use this file with AI assistants like ChatGPT, Claude, etc.`);
111+
}
112+
113+
// Run the script
114+
try {
115+
generateLLMContext();
116+
} catch (error) {
117+
console.error('❌ Error generating LLM context:', error);
118+
process.exit(1);
119+
}

0 commit comments

Comments
 (0)