Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions website/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Beautiful Soup": "beautifulsoup4",
"Cacheops": "django-cacheops",
"Chroma": "chromadb",
"Colour": "colour-science",
"Coverage.py": "coverage",
"Django AI Skills": "django-ai-plugins",
"Django ORM": "django.db.models",
Expand Down Expand Up @@ -340,8 +341,12 @@ def link_intro_picks(text: str, entry_names: Sequence[str]) -> str:
for i, line in enumerate(lines):
if not line.startswith("- "):
break
situation, _, pick = line.rpartition(": ")
lines[i] = f"{situation}: {link_pick_names(pick, slugs_by_key)}"
# A line can pair several situations with their picks: "- Physical units: Pint; astronomy: Astropy"
segments = []
for segment in line.split("; "):
situation, sep, pick = segment.rpartition(": ")
segments.append(f"{situation}{sep}{link_pick_names(pick, slugs_by_key)}" if sep else segment)
lines[i] = "; ".join(segments)
return head + marker + "\n".join(lines)


Expand Down
13 changes: 13 additions & 0 deletions website/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,3 +1645,16 @@ def test_links_pick_aliases_to_entry_rows(self, tmp_path):
path.write_text("Use w1.\n\nHow to choose:\n\n- Vision: OpenCV\n", encoding="utf-8")
intro_html, _, _, _ = load_category_intro(path, ["opencv-python"])
assert '<li>Vision: <a href="#entry-opencv-python">OpenCV</a></li>' in intro_html

def test_links_every_pick_on_a_line_pairing_several_situations(self, tmp_path):
path = tmp_path / "widgets.md"
path.write_text("Use w1.\n\nHow to choose:\n\n- Physical units: Pint; astronomy: Astropy; seismology: ObsPy\n- Colour science: Colour; math animations: Manim\n", encoding="utf-8")
intro_html, _, _, _ = load_category_intro(path, ["pint", "astropy", "obspy", "colour-science", "manim"])
assert '<li>Physical units: <a href="#entry-pint">Pint</a>; astronomy: <a href="#entry-astropy">Astropy</a>; seismology: <a href="#entry-obspy">ObsPy</a></li>' in intro_html
assert '<li>Colour science: <a href="#entry-colour-science">Colour</a>; math animations: <a href="#entry-manim">Manim</a></li>' in intro_html

def test_leaves_a_pick_line_without_a_situation_unchanged(self, tmp_path):
path = tmp_path / "widgets.md"
path.write_text("Use w1.\n\nHow to choose:\n\n- Django for everything\n", encoding="utf-8")
intro_html, _, _, _ = load_category_intro(path, ["Django"])
assert "<li>Django for everything</li>" in intro_html
Loading