Merge pull request #145 from DARC-e-V/fix-swl-index

fix: index and swl
This commit is contained in:
Matthias Jung
2026-08-26 14:13:39 +02:00
committed by GitHub
2 changed files with 54 additions and 0 deletions
+10
View File
@@ -657,6 +657,16 @@ class Build:
"editions": [],
},
)
if edition != "SWL" and question_entry["editions"] == ["SWL"]:
# SWL reuses questions from the regular courses, but can place
# them in SWL-specific chapters. The question index exposes a
# single canonical location, so prefer the first regular
# course occurrence. Pure SWL questions keep their location.
question_entry.update(
section=section_ident,
chapter_title=chapter_title,
section_title=section_title,
)
if edition not in question_entry["editions"]:
question_entry["editions"].append(edition)
+44
View File
@@ -102,3 +102,47 @@ def test_lowercase_swl_toc_is_supported(tmp_path):
build.build_edition("SWL")
assert (tmp_path / "build" / "SWL_course_index.html").exists()
assert (tmp_path / "build" / "SWL_swl_intro.html").exists()
def test_regular_course_location_takes_precedence_for_shared_swl_question(tmp_path):
prepare_content(tmp_path, include_swl=True)
build = Build(Config(content_path=tmp_path, build_path=tmp_path / "build"))
build._Build__collect_question_occurrences(
"SWL",
"SWL-Kapitel",
"swl_buchstabieralphabet",
"SWL-Buchstabieralphabet",
"[question:NA101]",
)
build._Build__collect_question_occurrences(
"N",
"Erste Schritte",
"buchstabiertafel",
"Internationale Buchstabiertafel",
"[question:NA101]",
)
assert build.question_index["NA101"] == {
"has_solution": False,
"section": "buchstabiertafel",
"chapter_title": "Erste Schritte",
"section_title": "Internationale Buchstabiertafel",
"editions": ["SWL", "N"],
}
def test_pure_swl_question_keeps_its_swl_location(tmp_path):
prepare_content(tmp_path, include_swl=True)
build = Build(Config(content_path=tmp_path, build_path=tmp_path / "build"))
build._Build__collect_question_occurrences(
"SWL",
"SWL-Kapitel",
"swl_eigene_fragen",
"SWL-Fragen",
"[question:SWL001]",
)
assert build.question_index["SWL001"]["section"] == "swl_eigene_fragen"
assert build.question_index["SWL001"]["editions"] == ["SWL"]