|
7 | 7 | TEMPLATE_DIR = "templates" |
8 | 8 |
|
9 | 9 | if __name__ == "__main__": |
| 10 | + # Load paperlibgroups |
10 | 11 | paperlibgroups = [] |
11 | 12 |
|
12 | 13 | for subdir, dirs, files in os.walk(TEMPLATE_DIR): |
|
19 | 20 |
|
20 | 21 | paperlibgroups.sort() |
21 | 22 |
|
| 23 | + # Load paperlibcategories |
| 24 | + paperlibcategories = [] |
| 25 | + |
| 26 | + for subdir, dirs, files in os.walk(TEMPLATE_DIR): |
| 27 | + for file in files: |
| 28 | + if file == "paperlibcategory.json": |
| 29 | + with open(os.path.join(subdir, file), "r") as f: |
| 30 | + paperlibcategories_dict = json.load(f) |
| 31 | + paperlibcategories.append( |
| 32 | + [paperlibcategories_dict["category_name"], |
| 33 | + subdir, |
| 34 | + paperlibcategories_dict["description"]]) |
| 35 | + |
| 36 | + paperlibcategories.sort() |
| 37 | + |
22 | 38 | with open("./output/README.md", "w") as f: |
23 | 39 | f.write("Version {}\n\n---\n\n".format(date.today().strftime("%Y-%m-%d"))) |
24 | 40 | f.write("# Included templates\n") |
25 | 41 |
|
26 | 42 | for lib in paperlibgroups: |
27 | | - f.write("\n## {}\n{}\n\n".format( |
| 43 | + f.write("\n## {}\n{}\n".format( |
28 | 44 | lib[0], |
29 | 45 | lib[2] |
30 | 46 | )) |
31 | 47 |
|
32 | | - for subdir, dirs, files in os.walk(TEMPLATE_DIR): |
33 | | - for file in files: |
34 | | - if file == "printablepaperlib.json": |
35 | | - if subdir.startswith(lib[1]): |
36 | | - with open(os.path.join(subdir, file), "r") as j: |
37 | | - printablepaperlib_dict = json.load(j) |
38 | | - f.write( |
39 | | - "- {} (v{})\n".format( |
40 | | - printablepaperlib_dict["template_name"].replace( |
41 | | - "_", "\\_"), |
42 | | - printablepaperlib_dict["version"] |
43 | | - )) |
| 48 | + for cat in paperlibcategories: |
| 49 | + if not(cat[1].startswith(lib[1]+"/")): |
| 50 | + break |
| 51 | + |
| 52 | + f.write("\n### {}\n{}\n\n".format( |
| 53 | + cat[0], |
| 54 | + cat[2] |
| 55 | + )) |
| 56 | + |
| 57 | + for subdir, dirs, files in os.walk(TEMPLATE_DIR): |
| 58 | + for file in files: |
| 59 | + if file == "printablepaperlib.json": |
| 60 | + if subdir.startswith(lib[1]+"/") and subdir.startswith(cat[1]+"/"): |
| 61 | + with open(os.path.join(subdir, file), "r") as j: |
| 62 | + printablepaperlib_dict = json.load(j) |
| 63 | + f.write( |
| 64 | + "- {} (v{})\n".format( |
| 65 | + printablepaperlib_dict["template_name"].replace( |
| 66 | + "_", "\\_"), |
| 67 | + printablepaperlib_dict["version"] |
| 68 | + )) |
0 commit comments