mirror of
https://github.com/vinta/awesome-python.git
synced 2026-11-20 06:40:51 +00:00
fix(website): link every pick on intro lines that pair several situations
link_intro_picks split each "How to choose" bullet at its last ": ", so on lines like "- Physical units: Pint; astronomy: Astropy; seismology: ObsPy" only the final pick was linked. Split on "; " first and link each pair. Add the Colour -> colour-science alias, and leave a bullet without a ": " unchanged instead of rewriting it to ": - ...", which dropped the whole list.
This commit is contained in:
parent
234dee17f1
commit
cddcbe5169
2 changed files with 20 additions and 2 deletions
|
|
@ -46,6 +46,7 @@ PICK_ALIASES = {
|
|||
"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",
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1645,3 +1645,16 @@ class TestLoadCategoryIntro:
|
|||
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…
Add table
Add a link
Reference in a new issue