From b039f790ca9a23b89c6cd18aacf0d71ec9cde339 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Wed, 21 Oct 2026 22:44:48 +0800 Subject: [PATCH] feat: keep only the lead above the table for an intro without a pick list An intro without a "How to choose" list, as a one-project category has no picks to compare, rendered all of its guide paragraphs above the table, pushing the table down. It now shows the lead above the table and moves the rest into the guide. Co-Authored-By: Claude --- website/build.py | 5 +++-- website/tests/test_build.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) 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") == ("", "", "", "")