Skip to content

Instantly share code, notes, and snippets.

@rglover
Created July 7, 2025 22:32
Show Gist options
  • Save rglover/6b886848a5e32fb60c89be3c4bbf6423 to your computer and use it in GitHub Desktop.
Save rglover/6b886848a5e32fb60c89be3c4bbf6423 to your computer and use it in GitHub Desktop.
Takes markdown files in a given path, concatenates them into a single string, and outputs the file at the specified path
import fs from 'fs';
import path from 'path';
const generate_llm_txt = (dir_path, output_path = 'llm.txt') => {
const read_markdown_files = (dir) => {
let files_content = '';
const files = fs.readdirSync(dir);
files.forEach((file) => {
const file_path = path.join(dir, file);
const stat = fs.statSync(file_path);
if (stat.isDirectory()) {
files_content += read_markdown_files(file_path);
} else if (file_path.endsWith('.md')) {
files_content += fs.readFileSync(file_path, 'utf-8') + '\n';
}
});
return files_content;
};
const all_content = read_markdown_files(dir_path);
fs.writeFileSync(output_path, all_content);
};
export default generate_llm_txt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment