forked from PIP-Labs-RE/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_it.py
More file actions
77 lines (64 loc) · 2.73 KB
/
add_it.py
File metadata and controls
77 lines (64 loc) · 2.73 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
74
75
76
77
#!/usr/bin/env python3
import json
import sys
import argparse
def find_additional_resources_section(navigation):
"""Find the Additional Resources section specifically in the Network tab"""
for tab in navigation.get("tabs", []):
for group in tab.get("groups", []):
if any(page == "network/more/additional-resources" for page in group.get("pages", [])):
return group
if group.get("group") == "Additional Resources":
return group
for page in group.get("pages", []):
if isinstance(page, dict) and page.get("group") == "Additional Resources":
return page
return None
def add_file_to_navigation(config, file_path):
"""Add a new file to the navigation structure"""
file_path = file_path.lstrip('/')
if file_path.endswith('.md'):
file_path = file_path[:-3]
elif file_path.endswith('.mdx'):
file_path = file_path[:-4]
if file_path.startswith("network/more/"):
resources_section = find_additional_resources_section(config["navigation"])
if resources_section:
pages = resources_section.get("pages", [])
page_name = file_path
if page_name not in pages:
pages.append(page_name)
print(f"Added '{page_name}' to the Additional Resources section")
return True
else:
print(f"File '{page_name}' already exists in navigation")
return False
else:
print("Could not find the Additional Resources section in the navigation")
return False
else:
print(f"Could not find appropriate position for '{file_path}' in navigation structure")
return False
def main():
parser = argparse.ArgumentParser(description='Add a file to the navigation structure in the docs.json file')
parser.add_argument('file_path', help='Path of the file to add (relative to content root)')
parser.add_argument('--config', default='docs.json', help='Path to the docs.json configuration file')
args = parser.parse_args()
try:
with open(args.config, 'r') as f:
config = json.load(f)
except Exception as e:
print(f"Error reading configuration file: {e}")
return 1
success = add_file_to_navigation(config, args.file_path)
if success:
try:
with open(args.config, 'w') as f:
json.dump(config, f, indent=2)
print(f"Updated configuration file: {args.config}")
except Exception as e:
print(f"Error writing configuration file: {e}")
return 1
return 0
if __name__ == '__main__':
sys.exit(main())