-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_nav.py
More file actions
35 lines (31 loc) · 1.3 KB
/
Copy pathcreate_nav.py
File metadata and controls
35 lines (31 loc) · 1.3 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
import os
import yaml
def generate_nav(directory, base_path=""):
"""
Recursively generates a navigation structure for a directory.
"""
nav = []
for item in sorted(os.listdir(directory)):
item_path = os.path.join(directory, item)
if os.path.isdir(item_path): # If it's a directory
sub_nav = generate_nav(item_path, base_path=os.path.join(base_path, item))
if sub_nav:
# Replace underscores with spaces in the directory name
nav.append({item.replace("_", " "): sub_nav})
elif item.endswith('.md'): # If it's a Markdown file
# Replace underscores with spaces in the file name (without extension)
nav.append({item[:-3].replace("_", " "): os.path.join(base_path, item)})
return nav
def save_nav_to_file(nav, output_file):
"""
Saves the generated navigation to a YAML file.
"""
with open(output_file, 'w') as f:
yaml.dump(nav, f, default_flow_style=False, sort_keys=False)
if __name__ == "__main__":
# Change 'docs' to the root directory of your documentation files
docs_directory = "docs"
output_file = "nav.yml"
navigation = generate_nav(docs_directory)
save_nav_to_file(navigation, output_file)
print(f"Navigation file saved to {output_file}")