-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.py
25 lines (22 loc) · 893 Bytes
/
cleanup.py
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
import os
input_dir = "./docs"
for root, dirs, files in os.walk(input_dir):
for filename in files:
if filename.endswith(".md") or filename.endswith(".mdx"):
input_path = os.path.join(root, filename)
with open(input_path, "r") as input_file:
contents = input_file.read()
while True:
start = contents.find("---")
if start == -1:
break
end = contents.find("---", start + 3)
if end == -1:
break
contents = contents[:start] + contents[end + 3 :]
index = contents.find("##")
if index >= 0:
contents = contents[index:]
contents = f"\n\n# {filename}\n{contents}"
with open("data.txt", "a") as output_file:
output_file.write(contents)