Skip to content

Commit 1b0acee

Browse files
committed
Updated script for handling separation of content
Signed-off-by: Saif Ul Islam <[email protected]>
1 parent 174939a commit 1b0acee

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

scripts/documentation.py

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Package imports
1414
import json
1515
import os
16+
import re
1617

1718

1819
def main():
@@ -37,15 +38,68 @@ def main():
3738
markdown_list.sort()
3839

3940
for index, file in enumerate(markdown_list):
41+
4042
with open(f'./sphinx-docs/_build/markdown/{file}', mode='r') as markdown_content:
41-
generated_markdown = ' '.join(markdown_content.readlines())
42-
43-
with open(f'./docs/docs/sdk/{file}', mode='w') as documentation_handle:
44-
documentation_handle.writelines('---\n'
45-
f'sidebar_position: {index}\n'
46-
'---\n'
47-
'\n'
48-
f'{generated_markdown}')
43+
generated_markdown = ''.join(markdown_content.readlines())
44+
45+
if file == 'index.md':
46+
47+
generated_markdown = generated_markdown.replace('src’s', 'the Mapillary’s Python SDK')
48+
49+
with open('./docs/docs/Table Of Contents.md', mode='w') as index_file:
50+
index_file.writelines('---\n'
51+
f'sidebar position: 1\n'
52+
'---\n'
53+
'\n'
54+
f'{generated_markdown}')
55+
56+
else:
57+
58+
package = generated_markdown[:generated_markdown.find('\n')].split(' package')[0][2:]
59+
60+
if not os.path.exists(f'./docs/docs/{package}'):
61+
os.mkdir(f'./docs/docs/{package}')
62+
63+
with open(f'./docs/docs/{package}/_category_.json', mode='w') as metadata_file:
64+
json.dump({
65+
"label": package.replace('.', ' ').title(),
66+
}, metadata_file, indent=4)
67+
68+
with open(f'./docs/docs/{package}/{package}.md', mode='w') as index_file:
69+
index_file.writelines('---\n'
70+
f'sidebar position: 2\n'
71+
'---\n'
72+
'\n'
73+
f'{package}')
74+
75+
modules = re.findall(r'## .*? module', generated_markdown)
76+
77+
for iteration in range(0, len(modules)):
78+
79+
# If not last iteration
80+
if not iteration == len(modules) - 1:
81+
82+
start_pos = re.search(modules[iteration], generated_markdown).end() + 1
83+
84+
end_pos = re.search(modules[iteration + 1], generated_markdown).start() - 1
85+
86+
# Else, we are at the last iteration
87+
else:
88+
89+
start_pos = re.search(modules[iteration], generated_markdown).end() + 1
90+
91+
end_pos = len(generated_markdown)
92+
93+
extracted_module = generated_markdown[start_pos:end_pos]
94+
95+
module_name = modules[iteration][3:-7]
96+
97+
with open(f'./docs/docs/{package}/{module_name}.md', mode='w') as markdown_handler:
98+
markdown_handler.writelines('---\n'
99+
f'sidebar position: {iteration + 2}\n'
100+
'---\n'
101+
'\n'
102+
f'{extracted_module}')
49103

50104

51105
if __name__ == '__main__':

0 commit comments

Comments
 (0)