This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature.py
40 lines (36 loc) · 1.56 KB
/
feature.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import re
import json
def parse():
with open("./feature.json") as f:
json_data = json.load(f)
with open('./docs/feature-boiler.md', 'rb') as f:
pattern = re.compile('<!--start (?:.*?)-->((.|\n)*?)<!--end-->')
name = re.compile('<!--start (.*?)-->')
chunk = f.read().decode('utf-8')
matches = pattern.finditer(chunk)
for match in matches:
full_block = match.group(0)
matched_content = match.group(1)
raw_project_name = name.search(full_block).group(1)
project_name = raw_project_name.replace("-", " ").title()
project = json_data.get(raw_project_name)
if project:
about = project['about'].replace('\\n', f' \n\t')
details = project['details'].replace('\\n', f' \n\t')
preview = project['preview']
content = (
f"<!--start {raw_project_name}-->"
f"""\n=== "About {project_name}"\n\t{about}"""
f"""\n=== "Project Details"\n\t{details}"""
)
if preview == 1:
image_uri = project['image_uri']
content += f"""\n=== "Preview"\n\t![{project_name}]({image_uri})\n<!--end-->"""
else:
content += "\n<!--end-->"
chunk = chunk.replace(full_block, content)
with open('./docs/featured.md', 'wb') as f:
f.write(chunk.encode('utf-8'))
if __name__ == '__main__':
parse()
print("Done file editing")