2"""Generate index.md from template using session configuration and figure URLs."""
4import yaml
5from pathlib import Path
6from jinja2 import Template
8# Load sessions configuration
9with open("sessions.yaml", "r") as f:
10 config = yaml.safe_load(f)
12# Read figure URLs for each session
13sessions_with_urls = []
14for session in config["sessions"]:
15 session_id = session["session_id"]
16 url_file = Path(f"figures/{session_id}.url")
18 if url_file.exists():
19 with open(url_file, "r") as f:
20 figure_url = f.read().strip()
21 else:
22 # Placeholder if URL file doesn't exist yet
23 figure_url = "# Figure not yet generated"
25 session_with_url = session.copy()
26 session_with_url["figure_url"] = figure_url
27 sessions_with_urls.append(session_with_url)
29# Load and render template
30with open("templates/index.md.jinja", "r") as f:
31 template = Template(f.read())
33rendered = template.render(
34 dandiset_id=config["dandiset_id"],
35 sessions=sessions_with_urls
36)
38# Write output
39with open("index.md", "w") as f:
40 f.write(rendered)
42print(f"Generated index.md with {len(sessions_with_urls)} sessions")