diff --git a/website/build.py b/website/build.py index 5078421c..9085920a 100755 --- a/website/build.py +++ b/website/build.py @@ -351,7 +351,8 @@ def load_category_intro(path: Path, entry_names: Sequence[str] = ()) -> tuple[st Returns the part shown above the table, the guide shown below it, and the first paragraph as plain text for the meta description and as HTML for - group pages. A file without the list keeps everything above the table. + group pages. A file without the list, like a one-project category's, + keeps only its lead above the table. Returns empty strings if the category has no intro file. """ if not path.exists(): @@ -364,7 +365,7 @@ def load_category_intro(path: Path, entry_names: Sequence[str] = ()) -> tuple[st child.attrSet("target", "_blank") child.attrSet("rel", "noopener") lead = next(node for node in SyntaxTreeNode(tokens).children if node.type == "paragraph") - split_at = len(tokens) + split_at = next(j for j, token in enumerate(tokens) if token.type == "paragraph_close" and token.level == 0) + 1 for i, token in enumerate(tokens): if token.type == "inline" and token.level == 1 and token.content == "How to choose:" and i + 2 < len(tokens) and tokens[i + 2].type == "bullet_list_open": split_at = next(j for j in range(i + 3, len(tokens)) if tokens[j].type == "bullet_list_close" and tokens[j].level == 0) + 1 diff --git a/website/tests/test_build.py b/website/tests/test_build.py index e567c84b..5b3cd15a 100644 --- a/website/tests/test_build.py +++ b/website/tests/test_build.py @@ -1673,12 +1673,12 @@ class TestLoadCategoryIntro: assert lead == "Use w1 for most apps." assert lead_html == "

Use w1 for most apps.

\n" - def test_keeps_everything_above_table_without_how_to_choose_list(self, tmp_path): + def test_splits_after_lead_without_how_to_choose_list(self, tmp_path): path = tmp_path / "widgets.md" path.write_text("Use w1.\n\n- Small apps: w1\n\nConfigure w1 once.\n", encoding="utf-8") intro_html, guide_html, _, _ = load_category_intro(path) - assert "Configure w1 once." in intro_html - assert guide_html == "" + assert intro_html == "

Use w1.

\n" + assert guide_html == "\n

Configure w1 once.

\n" def test_returns_empty_strings_without_intro_file(self, tmp_path): assert load_category_intro(tmp_path / "missing.md") == ("", "", "", "")