From 70a8255289eb5ffc03621dc2e9b32769463dd624 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 3 May 2026 08:35:55 +0800 Subject: [PATCH] feat(website): add /categories/built-in/ page for Built-in tag filter Register Built-in as a navigable filter path alongside regular category and group slugs, emit the page during build, add it to the sitemap, and wire the Built-in tag buttons in index.html and category.html to navigate there via data-url. Co-Authored-By: Claude --- website/build.py | 35 ++++++++++++++++++++++++++++++++- website/templates/category.html | 6 +++++- website/templates/index.html | 6 +++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/website/build.py b/website/build.py index 8fed7860..5a753a65 100644 --- a/website/build.py +++ b/website/build.py @@ -20,6 +20,11 @@ SITE_URL = "https://awesome-python.com/" SITEMAP_URL = f"{SITE_URL}sitemap.xml" SITEMAP_NS = "http://www.sitemaps.org/schemas/sitemap/0.9" +BUILTIN_FILTER = "Built-in" +BUILTIN_SLUG = "built-in" +BUILTIN_PATH = f"/categories/{BUILTIN_SLUG}/" +BUILTIN_PUBLIC_URL = f"{SITE_URL}categories/{BUILTIN_SLUG}/" + SOURCE_TYPE_DOMAINS = { "docs.python.org": "Built-in", "gitlab.com": "GitLab", @@ -287,7 +292,7 @@ def build(repo_root: Path) -> None: categories = [cat for g in parsed_groups for cat in g["categories"]] cat_slugs = [cat["slug"] for cat in categories] group_slugs = [g["slug"] for g in parsed_groups] - all_top_level_slugs = cat_slugs + group_slugs + all_top_level_slugs = cat_slugs + group_slugs + [BUILTIN_SLUG] duplicates = {s for s in all_top_level_slugs if all_top_level_slugs.count(s) > 1} if duplicates: raise ValueError( @@ -325,6 +330,9 @@ def build(repo_root: Path) -> None: for entry in entries: for sub in entry.get("subcategories", []): filter_urls[sub["value"]] = sub["url"] + builtin_entries = [e for e in entries if e.get("source_type") == BUILTIN_FILTER] + if builtin_entries: + filter_urls[BUILTIN_FILTER] = BUILTIN_PATH env = Environment( loader=FileSystemLoader(website / "templates"), @@ -402,6 +410,29 @@ def build(repo_root: Path) -> None: encoding="utf-8", ) + if builtin_entries: + page_dir = categories_dir / BUILTIN_SLUG + page_dir.mkdir(parents=True, exist_ok=True) + synthetic = { + "name": BUILTIN_FILTER, + "slug": BUILTIN_SLUG, + "description": "", + "description_html": "", + } + (page_dir / "index.html").write_text( + tpl_category.render( + category=synthetic, + category_url=BUILTIN_PUBLIC_URL, + entries=builtin_entries, + total_categories=len(categories), + page_kind="built-in", + category_urls=category_urls, + current_path=BUILTIN_PATH, + filter_urls_json=filter_urls_json, + ), + encoding="utf-8", + ) + seen_subcats: set[tuple[str, str]] = set() for category in categories: cat_url_prefix = f"/categories/{category['slug']}/" @@ -455,6 +486,8 @@ def build(repo_root: Path) -> None: sitemap_urls = [(SITE_URL, sitemap_date)] sitemap_urls.extend((category_public_url(c), sitemap_date) for c in categories) sitemap_urls.extend((group_public_url(g["slug"]), sitemap_date) for g in parsed_groups) + if builtin_entries: + sitemap_urls.append((BUILTIN_PUBLIC_URL, sitemap_date)) for cat_slug, sub_slug in sorted(seen_subcats): sitemap_urls.append((subcategory_public_url(cat_slug, sub_slug), sitemap_date)) write_sitemap_xml(site_dir / "sitemap.xml", sitemap_urls) diff --git a/website/templates/category.html b/website/templates/category.html index 96ced7f5..bb97ae61 100644 --- a/website/templates/category.html +++ b/website/templates/category.html @@ -176,7 +176,11 @@ {% endif %} {% if entry.source_type == 'Built-in' %} - {% endif %} diff --git a/website/templates/index.html b/website/templates/index.html index 2f909644..7e79bdba 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -247,7 +247,11 @@ {{ entry.groups[0] }} {% if entry.source_type == 'Built-in' %} - {% endif %}