-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-indexs.py
More file actions
64 lines (50 loc) · 1.58 KB
/
generate-indexs.py
File metadata and controls
64 lines (50 loc) · 1.58 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
import os
from mdutils import MdUtils
def replace_numbers(string: str):
# print(string)
for i in range(0, 20):
if len(str(i)) == 1:
str_to_replace = '0' + str(i)
else:
str_to_replace = str(i)
if str_to_replace in string:
print(str_to_replace)
string = string.replace(str_to_replace, '')
return string
sections = os.listdir('docs')
sections.sort()
section_dict = {
'title': '',
'pages': []
}
nav = []
for page in sections:
excluded = ['.md', 'img', 'css', 'Historia', 'CNAME', '.html', 'LICENSE']
if any(exclusion in page for exclusion in excluded):
pass
else:
pages = os.listdir('docs/'+page)
pages.sort()
section_dict = {
'title': page,
'pages': pages
}
page_title = page.replace('-', ' ')
mdFile = MdUtils(file_name='docs/' + page + '/index.md',title=page_title)
link_list = []
for item in pages:
# item = item.replace('.md', '').replace('-',' ')
item_name = item.replace('.md', '')
item_name = item_name.replace('-' , ' ')
item_name = replace_numbers(item_name)
link = {
'text': item_name,
'url': './' + item
}
if 'index' not in item_name:
inline_link = mdFile.new_inline_link(link['url'],link['text'])
link_list.append(inline_link)
mdFile.new_list(link_list)
mdFile.create_md_file()
nav.append(section_dict)
# print(nav)