style(website): apply ruff format

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-05-03 12:23:55 +08:00
parent 432a1f4b71
commit 3d99f7336d
4 changed files with 28 additions and 42 deletions

View File

@@ -11,7 +11,6 @@ from itertools import batched
from pathlib import Path
import httpx
from build import extract_github_repo, load_stars
CACHE_MAX_AGE_HOURS = 12
@@ -53,10 +52,7 @@ def build_graphql_query(repos: Sequence[str]) -> str:
owner, name = repo.split("/", 1)
if not GITHUB_OWNER_RE.match(owner) or not GITHUB_NAME_RE.match(name):
continue
parts.append(
f'repo_{i}: repository(owner: "{owner}", name: "{name}") '
f"{{ stargazerCount owner {{ login }} defaultBranchRef {{ target {{ ... on Commit {{ committedDate }} }} }} }}"
)
parts.append(f'repo_{i}: repository(owner: "{owner}", name: "{name}") {{ stargazerCount owner {{ login }} defaultBranchRef {{ target {{ ... on Commit {{ committedDate }} }} }} }}')
if not parts:
return ""
return "query { " + " ".join(parts) + " }"

View File

@@ -229,18 +229,22 @@ def _parse_list_entries(
if sub_inline:
sub_link = _find_child(sub_inline, "link")
if sub_link:
also_see.append(AlsoSee(
name=render_inline_text(sub_link.children),
url=_href(sub_link),
))
also_see.append(
AlsoSee(
name=render_inline_text(sub_link.children),
url=_href(sub_link),
)
)
entries.append(ParsedEntry(
name=name,
url=url,
description=desc_html,
also_see=also_see,
subcategory=subcategory,
))
entries.append(
ParsedEntry(
name=name,
url=url,
description=desc_html,
also_see=also_see,
subcategory=subcategory,
)
)
return entries
@@ -275,7 +279,6 @@ def _build_section(name: str, body: list[SyntaxTreeNode]) -> ParsedSection:
)
def _is_bold_marker(node: SyntaxTreeNode) -> str | None:
"""Detect a bold-only paragraph used as a group marker.
@@ -321,11 +324,13 @@ def _parse_grouped_sections(
nonlocal current_group_name, current_group_cats
if current_group_cats:
name = current_group_name or "Other"
groups.append(ParsedGroup(
name=name,
slug=slugify(name),
categories=list(current_group_cats),
))
groups.append(
ParsedGroup(
name=name,
slug=slugify(name),
categories=list(current_group_cats),
)
)
current_group_name = None
current_group_cats = []

View File

@@ -17,18 +17,12 @@ class TestExtractGithubRepos:
assert result == {"psf/requests"}
def test_multiple_repos(self):
readme = (
"* [requests](https://github.com/psf/requests) - HTTP.\n"
"* [flask](https://github.com/pallets/flask) - Micro."
)
readme = "* [requests](https://github.com/psf/requests) - HTTP.\n* [flask](https://github.com/pallets/flask) - Micro."
result = extract_github_repos(readme)
assert result == {"psf/requests", "pallets/flask"}
def test_deduplicates(self):
readme = (
"* [a](https://github.com/org/repo) - A.\n"
"* [b](https://github.com/org/repo) - B."
)
readme = "* [a](https://github.com/org/repo) - A.\n* [b](https://github.com/org/repo) - B."
result = extract_github_repos(readme)
assert result == {"org/repo"}

View File

@@ -350,10 +350,7 @@ def _content_nodes(md_text: str) -> list[SyntaxTreeNode]:
class TestParseSectionEntries:
def test_flat_entries(self):
nodes = _content_nodes(
"- [django](https://example.com/d) - A web framework.\n"
"- [flask](https://example.com/f) - A micro framework.\n"
)
nodes = _content_nodes("- [django](https://example.com/d) - A web framework.\n- [flask](https://example.com/f) - A micro framework.\n")
entries = _parse_section_entries(nodes)
assert len(entries) == 2
assert entries[0]["name"] == "django"
@@ -370,13 +367,7 @@ class TestParseSectionEntries:
assert entries[0]["description"] == ""
def test_subcategorized_entries(self):
nodes = _content_nodes(
"- Algorithms\n"
" - [algos](https://x.com/a) - Algo lib.\n"
" - [sorts](https://x.com/s) - Sort lib.\n"
"- Design Patterns\n"
" - [patterns](https://x.com/p) - Pattern lib.\n"
)
nodes = _content_nodes("- Algorithms\n - [algos](https://x.com/a) - Algo lib.\n - [sorts](https://x.com/s) - Sort lib.\n- Design Patterns\n - [patterns](https://x.com/p) - Pattern lib.\n")
entries = _parse_section_entries(nodes)
assert len(entries) == 3
assert entries[0]["name"] == "algos"
@@ -432,7 +423,7 @@ class TestParseSectionEntries:
assert cats[0]["entry_count"] == 3
def test_description_html_escapes_xss(self):
nodes = _content_nodes('- [lib](https://x.com) - A <script>alert(1)</script> lib.\n')
nodes = _content_nodes("- [lib](https://x.com) - A <script>alert(1)</script> lib.\n")
entries = _parse_section_entries(nodes)
assert "<script>" not in entries[0]["description"]
assert "&lt;script&gt;" in entries[0]["description"]