Card context
This commit is contained in:
@@ -79,7 +79,17 @@ def build_section_url(relative_path: str, section_index: int) -> str:
|
||||
return f"/api/program/assets/{token}/sections/{section_index}"
|
||||
|
||||
|
||||
def extract_svg_sections(svg_path: Path) -> list[dict]:
|
||||
def find_section_context_path(svg_path: Path, asset_number: int, section_number: int) -> Path | None:
|
||||
context_dir = svg_path.parent.parent / "card_contexts" / svg_path.stem
|
||||
candidates = [
|
||||
context_dir / f"Fiche{asset_number}Card{section_number}.md",
|
||||
context_dir / f"fiche_{asset_number:02d}_card_{section_number:02d}.md",
|
||||
context_dir / f"card_{section_number:02d}.md",
|
||||
]
|
||||
return next((candidate for candidate in candidates if candidate.exists()), None)
|
||||
|
||||
|
||||
def extract_svg_sections(svg_path: Path, asset_number: int | None = None) -> list[dict]:
|
||||
text = svg_path.read_text(encoding="utf-8", errors="ignore")
|
||||
sections: list[dict] = []
|
||||
pattern = re.compile(
|
||||
@@ -97,10 +107,16 @@ def extract_svg_sections(svg_path: Path) -> list[dict]:
|
||||
raw_title = re.sub(r"<[^>]+>", "", title_match.group("title") if title_match else "")
|
||||
title = html.unescape(raw_title).strip() or f"Étape {len(sections) + 1}"
|
||||
margin = 28
|
||||
section_number = len(sections) + 1
|
||||
context_path = find_section_context_path(svg_path, asset_number or 1, section_number)
|
||||
sections.append(
|
||||
{
|
||||
"index": len(sections),
|
||||
"title": title,
|
||||
"context_key": f"Fiche{asset_number or 1}Card{section_number}",
|
||||
"context": context_path.read_text(encoding="utf-8", errors="ignore").strip()
|
||||
if context_path
|
||||
else "",
|
||||
"view_box": [
|
||||
max(float(match.group("x")) - margin, 0),
|
||||
max(float(match.group("y")) - margin, 0),
|
||||
@@ -164,9 +180,9 @@ def list_lessons() -> list[dict]:
|
||||
title = first_heading or title
|
||||
|
||||
assets = []
|
||||
for svg_path in svg_files:
|
||||
for asset_index, svg_path in enumerate(svg_files, start=1):
|
||||
relative_path = svg_path.relative_to(CONTENT_ROOT).as_posix()
|
||||
sections = extract_svg_sections(svg_path)
|
||||
sections = extract_svg_sections(svg_path, asset_index)
|
||||
assets.append(
|
||||
{
|
||||
"name": svg_path.stem,
|
||||
|
||||
Reference in New Issue
Block a user