feat(website): add subcategory_path and subcategory_public_url helpers

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-05-03 00:08:04 +08:00
parent 4005c2ea82
commit 39d4b3db4b
2 changed files with 17 additions and 0 deletions

View File

@@ -92,6 +92,14 @@ def category_public_url(category: ParsedSection) -> str:
return f"{SITE_URL}categories/{category['slug']}/"
def subcategory_path(category_slug: str, subcategory_slug: str) -> str:
return f"/categories/{category_slug}/{subcategory_slug}/"
def subcategory_public_url(category_slug: str, subcategory_slug: str) -> str:
return f"{SITE_URL}categories/{category_slug}/{subcategory_slug}/"
def write_sitemap_xml(path: Path, urls: Sequence[tuple[str, str]]) -> None:
ET.register_namespace("", SITEMAP_NS)
urlset = ET.Element(f"{{{SITEMAP_NS}}}urlset")

View File

@@ -16,6 +16,7 @@ from build import (
extract_github_repo,
load_stars,
sort_entries,
subcategory_path,
)
from readme_parser import parse_readme, slugify
@@ -81,6 +82,14 @@ class TestSlugify:
assert slugify(" Date and Time ") == "date-and-time"
class TestSubcategoryPath:
def test_builds_path(self):
assert subcategory_path("web-frameworks", "synchronous") == "/categories/web-frameworks/synchronous/"
def test_trailing_slash(self):
assert subcategory_path("a", "b").endswith("/")
# ---------------------------------------------------------------------------
# build (integration)
# ---------------------------------------------------------------------------