-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-llm-docs.js
More file actions
73 lines (56 loc) · 2.04 KB
/
Copy pathgenerate-llm-docs.js
File metadata and controls
73 lines (56 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const fs = require('fs');
const path = require('path');
const docsDir = path.join(process.cwd(), 'docs');
const staticDir = path.join(process.cwd(), 'static');
const outputFile = path.join(staticDir, 'llms-full.txt');
const llmsTxtFile = path.join(staticDir, 'llms.txt');
// Ensure static directory exists
if (!fs.existsSync(staticDir)) {
fs.mkdirSync(staticDir, { recursive: true });
}
function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function(file) {
const fullPath = path.join(dirPath, file);
if (fs.statSync(fullPath).isDirectory()) {
arrayOfFiles = getAllFiles(fullPath, arrayOfFiles);
} else {
if (file.endsWith('.md') || file.endsWith('.mdx')) {
arrayOfFiles.push(fullPath);
}
}
});
return arrayOfFiles;
}
function generateContent() {
const files = getAllFiles(docsDir);
// Sort files for consistent output, preferably by path
files.sort();
let fullContent = "# Rhumb Language Documentation\n\n";
fullContent += "This file contains the full documentation for the Rhumb programming language.\n\n";
files.forEach(file => {
const content = fs.readFileSync(file, 'utf8');
// Check for draft: true in frontmatter
const draftMatch = content.match(/^---\s+[\s\S]*?draft:\s*true[\s\S]*?---/);
if (draftMatch) {
console.log(`Skipping draft: ${file}`);
return;
}
const relativePath = path.relative(docsDir, file);
fullContent += `\n\n--- START OF FILE: ${relativePath} ---\n\n`;
fullContent += content;
fullContent += `\n\n--- END OF FILE: ${relativePath} ---\n`;
});
fs.writeFileSync(outputFile, fullContent);
console.log(`Generated ${outputFile}`);
const llmsTxtContent = `# Rhumb Language Context
Project Name: Rhumb Language
Description: The Rhumb programming language documentation.
Documentation Sets:
- Full Documentation: /llms-full.txt
`;
fs.writeFileSync(llmsTxtFile, llmsTxtContent);
console.log(`Generated ${llmsTxtFile}`);
}
generateContent();