From 532d93d4364ed69068cf9e15b113e9191067a7ee Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 3 May 2026 00:19:14 +0800 Subject: [PATCH] feat(website): generate static pages for groups under /categories/ Co-Authored-By: Claude --- website/build.py | 26 ++++++++++++++++++++++++ website/tests/test_build.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/website/build.py b/website/build.py index 0583a464..250c1666 100644 --- a/website/build.py +++ b/website/build.py @@ -92,6 +92,10 @@ def category_public_url(category: ParsedSection) -> str: return f"{SITE_URL}categories/{category['slug']}/" +def group_public_url(group_slug: str) -> str: + return f"{SITE_URL}categories/{group_slug}/" + + def subcategory_path(category_slug: str, subcategory_slug: str) -> str: return f"/categories/{category_slug}/{subcategory_slug}/" @@ -351,6 +355,28 @@ def build(repo_root: Path) -> None: category_url=category_public_url(category), entries=category_entries, total_categories=len(categories), + page_kind="category", + ), + encoding="utf-8", + ) + + for group in parsed_groups: + group_entries = [entry for entry in entries if group["name"] in entry["groups"]] + page_dir = categories_dir / group["slug"] + page_dir.mkdir(parents=True, exist_ok=True) + synthetic = { + "name": group["name"], + "slug": group["slug"], + "description": "", + "description_html": "", + } + (page_dir / "index.html").write_text( + tpl_category.render( + category=synthetic, + category_url=group_public_url(group["slug"]), + entries=group_entries, + total_categories=len(categories), + page_kind="group", ), encoding="utf-8", ) diff --git a/website/tests/test_build.py b/website/tests/test_build.py index ead89d57..5fa155fd 100644 --- a/website/tests/test_build.py +++ b/website/tests/test_build.py @@ -542,6 +542,46 @@ class TestBuild: assert 'id="hero-category-heading">Browse by category' in html assert 'class="hero-category-link" href="/categories/ai-and-agents/"' in html + def test_build_creates_group_pages(self, tmp_path): + readme = textwrap.dedent("""\ + # T + + --- + + **AI & ML** + + ## Deep Learning + + - [dl1](https://example.com/dl1) - DL. + + ## Machine Learning + + - [ml1](https://example.com/ml1) - ML. + + **Web Development** + + ## Web Frameworks + + - [wf1](https://example.com/wf1) - WF. + + # Contributing + + Done. + """) + self._copy_real_templates(tmp_path) + (tmp_path / "README.md").write_text(readme, encoding="utf-8") + build(tmp_path) + + site = tmp_path / "website" / "output" + ai_ml = (site / "categories" / "ai-ml" / "index.html").read_text(encoding="utf-8") + web_dev = (site / "categories" / "web-development" / "index.html").read_text(encoding="utf-8") + + assert "dl1" in ai_ml + assert "ml1" in ai_ml + assert "wf1" not in ai_ml + assert "wf1" in web_dev + assert "dl1" not in web_dev + # --------------------------------------------------------------------------- # extract_github_repo