Sort entries by stars descending, then name ascending. Three tiers: starred entries first, stdlib second, other non-starred last.
(entries: Sequence[TemplateEntry])
| 97 | |
| 98 | |
| 99 | def sort_entries(entries: Sequence[TemplateEntry]) -> list[TemplateEntry]: |
| 100 | """Sort entries by stars descending, then name ascending. |
| 101 | |
| 102 | Three tiers: starred entries first, stdlib second, other non-starred last. |
| 103 | """ |
| 104 | |
| 105 | def sort_key(entry: TemplateEntry) -> tuple[int, int, int, str]: |
| 106 | stars = entry["stars"] |
| 107 | name = entry["name"].lower() |
| 108 | if stars is not None: |
| 109 | builtin = 1 if entry.get("source_type") == "Built-in" else 0 |
| 110 | return (0, -stars, builtin, name) |
| 111 | if entry.get("source_type") == "Built-in": |
| 112 | return (1, 0, 0, name) |
| 113 | return (2, 0, 0, name) |
| 114 | |
| 115 | return sorted(entries, key=sort_key) |
| 116 | |
| 117 | |
| 118 | def build_robots_txt() -> str: |
no outgoing calls