Skip to content

Commit 4e142d8

Browse files
committed
Update script to work without data.
1 parent af37555 commit 4e142d8

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ check:
4444
pnpm run astro check
4545

4646
build:
47-
pnpm update_data
4847
pnpm build
4948

5049
preview: RELEASES_DIR = $(VPS_PREVIEW_PATH)/$(SAFE_BRANCH)/releases

scripts/generate_content.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import json
1212
import shutil
1313
import yaml
14+
import sys
1415

1516
ROOT = pathlib.Path(__file__).parents[1]
1617

@@ -39,36 +40,41 @@ def load_json_data(filename, directory="src/data"):
3940
file_path = os.path.join(directory, f"{filename}.json")
4041

4142
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}")
4344

4445
print(f"Load {filename}.json from {directory}")
4546
with open(file_path, "r", encoding="utf-8") as file:
4647
return json.load(file)
4748

4849
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)
7278

7379

7480
if __name__ == "__main__":

0 commit comments

Comments
 (0)