|
11 | 11 | import json
|
12 | 12 | import shutil
|
13 | 13 | import yaml
|
| 14 | +import sys |
14 | 15 |
|
15 | 16 | ROOT = pathlib.Path(__file__).parents[1]
|
16 | 17 |
|
@@ -39,36 +40,41 @@ def load_json_data(filename, directory="src/data"):
|
39 | 40 | file_path = os.path.join(directory, f"{filename}.json")
|
40 | 41 |
|
41 | 42 | if not os.path.exists(file_path):
|
42 |
| - raise FileNotFoundError(f"File {filename}.json not found in {directory}") |
| 43 | + FileNotFoundError(f"File {filename}.json not found in {directory}") |
43 | 44 |
|
44 | 45 | print(f"Load {filename}.json from {directory}")
|
45 | 46 | with open(file_path, "r", encoding="utf-8") as file:
|
46 | 47 | return json.load(file)
|
47 | 48 |
|
48 | 49 | def generate_content() -> None:
|
49 |
| - speakers = load_json_data("speakers") |
50 |
| - sessions = load_json_data("sessions") |
51 |
| - schedule = load_json_data("schedule") |
52 |
| - |
53 |
| - for session in sessions.values(): |
54 |
| - session["speakers"] = [ |
55 |
| - speakers[speaker_id]["slug"] for speaker_id in session.get("speakers", []) |
56 |
| - ] |
57 |
| - |
58 |
| - for speaker in speakers.values(): |
59 |
| - speaker["submissions"] = [ |
60 |
| - sessions[session_id]["slug"] |
61 |
| - for session_id in speaker.get("submissions", []) |
62 |
| - if session_id in sessions |
63 |
| - ] |
64 |
| - |
65 |
| - write_mdx(sessions, ROOT / "src/content/sessions", "abstract") |
66 |
| - write_mdx(speakers, ROOT / "src/content/speakers", "biography") |
67 |
| - |
68 |
| - for day, data in schedule["days"].items(): |
69 |
| - path = ROOT / f"src/content/days/{day}.json" |
70 |
| - with path.open("w", encoding="utf-8") as f: |
71 |
| - json.dump(data, f, indent=2) |
| 50 | + files = ["speakers", "sessions", "schedule"] |
| 51 | + |
| 52 | + if any(not os.path.exists(f"src/data/{file}.json") for file in files): |
| 53 | + print("Nothing to generate. Missing data.") |
| 54 | + else: |
| 55 | + speakers = load_json_data("speakers") |
| 56 | + sessions = load_json_data("sessions") |
| 57 | + schedule = load_json_data("schedule") |
| 58 | + |
| 59 | + for session in sessions.values(): |
| 60 | + session["speakers"] = [ |
| 61 | + speakers[speaker_id]["slug"] for speaker_id in session.get("speakers", []) |
| 62 | + ] |
| 63 | + |
| 64 | + for speaker in speakers.values(): |
| 65 | + speaker["submissions"] = [ |
| 66 | + sessions[session_id]["slug"] |
| 67 | + for session_id in speaker.get("submissions", []) |
| 68 | + if session_id in sessions |
| 69 | + ] |
| 70 | + |
| 71 | + write_mdx(sessions, ROOT / "src/content/sessions", "abstract") |
| 72 | + write_mdx(speakers, ROOT / "src/content/speakers", "biography") |
| 73 | + |
| 74 | + for day, data in schedule["days"].items(): |
| 75 | + path = ROOT / f"src/content/days/{day}.json" |
| 76 | + with path.open("w", encoding="utf-8") as f: |
| 77 | + json.dump(data, f, indent=2) |
72 | 78 |
|
73 | 79 |
|
74 | 80 | if __name__ == "__main__":
|
|
0 commit comments