-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathcompile_llms_txt.py
More file actions
37 lines (29 loc) · 1.23 KB
/
compile_llms_txt.py
File metadata and controls
37 lines (29 loc) · 1.23 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
import os
def compile_llms_txt():
# Get the docs directory path (where this script is located)
docs_dir = os.path.dirname(os.path.abspath(__file__))
content = ''
# Define names of directories and files to exclude
excluded_names = {'tool'}
# Change to docs directory
os.chdir(docs_dir)
for root, _, files in os.walk('.'):
# Get the last part of the current directory
current_dir = os.path.basename(root)
if current_dir in excluded_names:
continue
for file in files:
if file.endswith('.mdx'):
if file in excluded_names:
continue
file_path = os.path.join(root, file)
relative_path = os.path.relpath(file_path, '.')
with open(file_path, 'r', encoding='utf-8') as f:
file_content = f.read()
content += f"## {relative_path}\n\n{file_content}\n\n"
# Write the complete content, replacing the existing file
output_path = os.path.join(docs_dir, 'llms.txt')
with open(output_path, 'w', encoding='utf-8') as f:
f.write(content)
if __name__ == "__main__":
compile_llms_txt()