mirror of
https://github.com/vinta/awesome-python.git
synced 2026-10-02 08:23:10 +08:00
feat: default-sort the website table by downloads per month
Entries with a download count now sort first (descending), with stars, then Built-in, then name as fallback tiers for entries that lack a count. main.js mirrors this in its default activeSort, clean URL check, and third-click reset target. Sorting by stars remains one header click away. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+9
-5
@@ -115,20 +115,24 @@ def load_downloads(path: Path) -> dict[str, int]:
|
||||
|
||||
|
||||
def sort_entries(entries: Sequence[TemplateEntry]) -> list[TemplateEntry]:
|
||||
"""Sort entries by stars descending, then name ascending.
|
||||
"""Sort entries by downloads descending, then name ascending.
|
||||
|
||||
Three tiers: starred entries first, stdlib second, other non-starred last.
|
||||
Four tiers: entries with download counts first, then starred entries by
|
||||
stars descending, then stdlib, then the rest.
|
||||
"""
|
||||
|
||||
def sort_key(entry: TemplateEntry) -> tuple[int, int, int, str]:
|
||||
downloads = entry["downloads"]
|
||||
stars = entry["stars"]
|
||||
name = entry["name"].lower()
|
||||
if downloads is not None:
|
||||
return (0, -downloads, 0, name)
|
||||
if stars is not None:
|
||||
builtin = 1 if entry.get("source_type") == "Built-in" else 0
|
||||
return (0, -stars, builtin, name)
|
||||
return (1, -stars, builtin, name)
|
||||
if entry.get("source_type") == "Built-in":
|
||||
return (1, 0, 0, name)
|
||||
return (2, 0, 0, name)
|
||||
return (2, 0, 0, name)
|
||||
return (3, 0, 0, name)
|
||||
|
||||
return sorted(entries, key=sort_key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user