-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatejekyll.py
84 lines (73 loc) · 2.57 KB
/
createjekyll.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
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
import glob
import json
import os
import sys
input_folder = "docs"
obj_schema_path = "schemas/arena-schema-files.json"
sec_nav_order = 1
sec_title = "ARENA Objects"
sec_sub_title = "Objects Schema"
def main():
args = sys.argv[1:]
print(args)
if len(args) == 0 or not os.path.isdir(args[0]):
os.mkdir(args[0])
output_folder = args[0]
# clean dest
for oldpath in glob.iglob(os.path.join(output_folder, "*.md")):
os.remove(oldpath)
# make jekyll index.md with objects list
md_lines = []
md_lines.append("---\n")
md_lines.append(f"title: {sec_sub_title}\n")
md_lines.append("layout: default\n")
md_lines.append(f"parent: {sec_title}\n")
md_lines.append("has_children: true\n")
md_lines.append("has_toc: false\n")
md_lines.append("---\n")
md_lines.append(
"\n<!--CAUTION: This file is autogenerated from https://github.com/arenaxr/arena-schemas. Changes made here may be overwritten.-->\n\n"
)
md_lines.append("# ARENA Message Objects\n")
md_lines.append("\n")
md_lines.append("|Object Message|Description|\n")
md_lines.append("| :--- | :--- |\n")
with open(obj_schema_path, "r") as json_file_all:
files = json.load(json_file_all)
for file in files:
filename = os.path.basename(files[file]["file"])
title = files[file]["title"]
desc = files[file]["description"]
md_lines.append(f"|[{title}]({filename[:-5]})|{desc}|\n")
out = "".join(md_lines)
index_path = os.path.join(output_folder, "index.md")
print(f"->{index_path}")
f = open(index_path, "w")
f.write(out)
f.close()
# make jekyll.md for each object
idx = 0
for filename in sorted(os.listdir(input_folder)):
with open(os.path.join(input_folder, filename), "r") as f:
text = f.read()
lines = text.split("\n")
md_lines = []
md_lines.append("---\n")
md_lines.append(f"title: {lines[1]}\n")
md_lines.append("layout: default\n")
md_lines.append(f"parent: {sec_sub_title}\n")
md_lines.append(f"grand_parent: {sec_title}\n")
md_lines.append("---\n")
md_lines.append(
"\n<!--CAUTION: This file is autogenerated from https://github.com/arenaxr/arena-schemas. Changes made here may be overwritten.-->\n\n"
)
md_lines.append(text)
out = "".join(md_lines)
md_path = os.path.join(output_folder, filename)
print(f"->{md_path}")
f = open(md_path, "w")
f.write(out)
f.close()
idx += 1
if __name__ == "__main__":
main()