feat(languages): add hidden languages picker and enrich language data

This commit is contained in:
shay
2026-04-18 13:39:44 -04:00
parent 5198eab86a
commit 3e70e4b4ef
6 changed files with 162 additions and 15 deletions
+31 -2
View File
@@ -463,6 +463,11 @@ def compute_languages(github_data: dict, hidden_languages: list[str] = None) ->
"""
Compute language distribution from repos.
Prefers per-repo byte breakdowns (`repo["language_bytes"]`) when present —
that matches GitHub's own "Most Used Languages" widget. Falls back to a
primary-language repo-count tally for payloads fetched before the
enrichment step landed.
Args:
github_data: GitHub profile data
hidden_languages: Optional list of languages to exclude (e.g., ["HTML", "CSS"])
@@ -471,12 +476,36 @@ def compute_languages(github_data: dict, hidden_languages: list[str] = None) ->
if hidden_languages is None:
hidden_languages = HIDDEN_LANGUAGES
hidden_set = {h for h in hidden_languages}
repos = github_data["repos"]
lang_counts = defaultdict(int)
byte_totals: dict[str, int] = defaultdict(int)
have_bytes = False
for r in repos:
lb = r.get("language_bytes") or {}
if not isinstance(lb, dict) or not lb:
continue
have_bytes = True
for lang, n in lb.items():
if lang and lang not in hidden_set:
byte_totals[lang] += int(n or 0)
if have_bytes and byte_totals:
total = sum(byte_totals.values()) or 1
return [
LanguageData(
language=lang,
percentage=round(size / total * 100, 1),
loc=size,
)
for lang, size in sorted(byte_totals.items(), key=lambda x: -x[1])
]
# Legacy fallback: repo-count by primary language.
lang_counts: dict[str, int] = defaultdict(int)
for r in repos:
lang = r.get("language")
if lang and lang not in hidden_languages:
if lang and lang not in hidden_set:
lang_counts[lang] += 1
total = sum(lang_counts.values()) or 1
+1 -1
View File
@@ -36,7 +36,7 @@ def icon_svg(kind: str, color: str) -> str:
icons = {
"commits": f'<circle cx="7" cy="7" r="3" fill="none" stroke="{color}" stroke-width="1.4"/><circle cx="7" cy="7" r="1" fill="{color}"/><line x1="7" y1="10" x2="7" y2="14" stroke="{color}" stroke-width="1.4"/><line x1="7" y1="0" x2="7" y2="4" stroke="{color}" stroke-width="1.4"/>',
"prs": f'<circle cx="4" cy="4" r="2" fill="none" stroke="{color}" stroke-width="1.2"/><circle cx="10" cy="10" r="2" fill="none" stroke="{color}" stroke-width="1.2"/><path d="M4 6v4c0 1.1.9 2 2 2h2" fill="none" stroke="{color}" stroke-width="1.2"/>',
"stars": f'<path d="M7 1l1.8 3.6 4 .6-2.9 2.8.7 4L7 10.2 3.4 12l.7-4L1.2 5.2l4-.6z" fill="{color}" opacity="0.85"/>',
"stars": f'<path d="M7 1l1.8 3.6 4 .6-2.9 2.8.7 4L7 10.2 3.4 12l.7-4L1.2 5.2l4-.6z" fill="none" stroke="{color}" stroke-width="1.2" stroke-linejoin="round"/>',
"repos": f'<rect x="2" y="1" width="10" height="12" rx="1.5" fill="none" stroke="{color}" stroke-width="1.2"/><line x1="5" y1="4" x2="9" y2="4" stroke="{color}" stroke-width="1"/><line x1="5" y1="6.5" x2="9" y2="6.5" stroke="{color}" stroke-width="1"/><line x1="5" y1="9" x2="7" y2="9" stroke="{color}" stroke-width="1"/>',
"followers": f'<circle cx="5" cy="4" r="2.5" fill="none" stroke="{color}" stroke-width="1.2"/><path d="M0.5 12c0-2.5 2-4 4.5-4s4.5 1.5 4.5 4" fill="none" stroke="{color}" stroke-width="1.2"/><circle cx="11" cy="3.5" r="1.8" fill="none" stroke="{color}" stroke-width="1"/><path d="M10 7.5c1.5 0 3.5 1 3.5 3" fill="none" stroke="{color}" stroke-width="1"/>',
}