-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sidebar.py
More file actions
24 lines (19 loc) · 806 Bytes
/
create_sidebar.py
File metadata and controls
24 lines (19 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
def create_sidebar(parent, sidebar, level=0):
indent = ' ' * level
for item in sorted(os.listdir(parent)):
path = os.path.join(parent, item)
if os.path.isdir(path):
if level == 0:
sidebar.write(f'\n{indent}**{item.upper()}**\n\n')
else:
sidebar.write(f'\n{indent}- {item}\n')
create_sidebar(path, sidebar, level + 1)
elif item.endswith('.md') and item != '_Sidebar.md':
# Remove the ".md" extension and folder names from the links in the sidebar
sidebar.write(f'{indent}- [{item[:-3]}]({item[:-3]})\n')
if level == 0:
sidebar.write('\n')
parent = 'wiki'
with open(os.path.join(parent, '_Sidebar.md'), 'w') as sidebar:
create_sidebar(parent, sidebar)