-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
91 lines (68 loc) · 2.62 KB
/
build.py
File metadata and controls
91 lines (68 loc) · 2.62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Creates documentation files in a common format
This repository has grown and now contains a big collection
of project descriptions. That makes ensuring a common
quality a problem.
So I now try out if having data files works, combined
with the automated creation of md files.
"""
import json
import io
def read_project_categories() -> dict:
with open('data/projects.json') as json_file:
data = json.load(json_file)
return data
def create_project_markdown(project, category) -> str:
result = []
index_filename = get_project_index_filename(project, category)
list_item = "- [" + project["id"] + "]"
list_item += "(" + index_filename + ") "
list_item += "\"" + project["nickname"] + "\", "
list_item += project["title"]
result.append(list_item)
return '\n'.join(result)
def create_project_list_with_level(category) -> str:
result = []
projects = sorted(category["projects"], key=lambda d: str(d['level']) + ":" + d['id'])
last_level = ""
for project in projects:
if last_level != project["level"]:
result.append("")
result.append("## Level " + str(project["level"]))
last_level = project["level"]
result.append(create_project_markdown(project, category))
return '\n'.join(result)
def create_project_list(category) -> str:
result = []
result.append("")
projects = sorted(category["projects"], key=lambda d: d['id'])
for project in projects:
result.append(create_project_markdown(project, category))
return '\n'.join(result)
def create_category_markdown(category) -> str:
result = []
result.append("# " + category["name"])
result.append("")
result.append(category["description"])
projects = category["projects"]
if "level" in projects[0]:
result.append(create_project_list_with_level(category))
else:
result.append(create_project_list(category))
return '\n'.join(result)
def get_project_index_filename(project, category) -> str:
return project["id"] + "/README.md"
def get_category_index_filename(category) -> str:
return category["folder"] + "/README.md"
def log(text):
print(" - " + text)
def write_file(filename, text):
with io.open(filename, 'w', encoding='utf8') as f:
f.write(text)
if __name__ == "__main__":
project_categories = read_project_categories()
for category in project_categories:
log("processing " + category["name"])
content = create_category_markdown(category)
filename = get_category_index_filename(category)
write_file(filename, content)