mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(tags): implement custom tag color merging and label support
This commit is contained in:
@@ -5,7 +5,7 @@ import { THEMES, TAG_COLORS, GRADE_COLORS, FOCUS_COLORS, LANG_COLORS, type Theme
|
||||
export type GradeData = {
|
||||
grade: string; score: number
|
||||
stats: Record<string, number>
|
||||
tags: { tag: string; source: string; confidence: number }[]
|
||||
tags: { tag: string; source: string; confidence: number; label?: string | null }[]
|
||||
breakdown: Record<string, number>
|
||||
}
|
||||
export type ImpactWeek = { week_start: string; commits: number }
|
||||
@@ -91,7 +91,7 @@ function renderGrade(data: GradeData, t: Theme, s?: { max_tags?: number }): stri
|
||||
let tagsSvg = '', tx = 0, ty = 0
|
||||
for (const tag of tags) {
|
||||
const tc = TAG_COLORS[tag.tag] ?? t.accent
|
||||
const label = formatTagLabel(tag.tag)
|
||||
const label = tag.label || formatTagLabel(tag.tag)
|
||||
const tw = Math.round(label.length * 6.6 + 18)
|
||||
const po = tag.source === 'earned' ? 0.9 : 0.55
|
||||
if (tx + tw > 340) { tx = 0; ty += 30 }
|
||||
|
||||
@@ -153,6 +153,18 @@ def enrollments_today() -> int:
|
||||
return row["count"] if row else 0
|
||||
|
||||
|
||||
def enrollment_rank(username: str) -> Optional[int]:
|
||||
"""1-based position in overall enrollment order by enrolled_at. Used by
|
||||
tag rules that reward early users (e.g. the 'founder' tag)."""
|
||||
with _settings_conn() as c:
|
||||
row = c.execute("SELECT enrolled_at FROM users WHERE username=?", (username,)).fetchone()
|
||||
if row is None:
|
||||
return None
|
||||
return c.execute(
|
||||
"SELECT COUNT(*) FROM users WHERE enrolled_at <= ?", (row["enrolled_at"],)
|
||||
).fetchone()[0]
|
||||
|
||||
|
||||
def get_settings(username: str) -> Optional[dict]:
|
||||
with _settings_conn() as c:
|
||||
row = c.execute("SELECT * FROM users WHERE username=?", (username,)).fetchone()
|
||||
|
||||
@@ -17,6 +17,7 @@ class TagData:
|
||||
tag: str
|
||||
source: str = "earned" # "earned" | "chosen"
|
||||
confidence: float = 1.0
|
||||
label: str | None = None # optional display override (e.g. "Founder #42")
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -191,6 +191,7 @@ def _compute_tags(github_data: dict, max_tags: int = None, custom_tags: list[str
|
||||
|
||||
# Apply threshold rules
|
||||
awarded_tags = []
|
||||
tag_label_overrides: dict[str, str] = {}
|
||||
|
||||
# Fullstack: >25% frontend AND >25% backend
|
||||
if category_percentages.get("Frontend", 0) > 0.25 and category_percentages.get("Backend", 0) > 0.25:
|
||||
@@ -237,9 +238,22 @@ def _compute_tags(github_data: dict, max_tags: int = None, custom_tags: list[str
|
||||
for tag in custom_tags:
|
||||
awarded_tags.append((tag, 1.0))
|
||||
|
||||
# Auto-awarded tags (username-specific + rule-based; see src/tag_rules.py).
|
||||
from . import tag_rules
|
||||
username = (github_data.get("user") or {}).get("login", "")
|
||||
for auto_tag, label in tag_rules.evaluate(username, github_data):
|
||||
awarded_tags.append((auto_tag, 1.0))
|
||||
if label:
|
||||
tag_label_overrides[auto_tag] = label
|
||||
|
||||
# Sort by confidence and limit to max_tags
|
||||
for tag, conf in sorted(awarded_tags, key=lambda x: -x[1])[:max_tags]:
|
||||
tags.append(TagData(tag=tag, source="earned" if conf < 1.0 else "custom", confidence=round(conf, 2)))
|
||||
tags.append(TagData(
|
||||
tag=tag,
|
||||
source="earned" if conf < 1.0 else "custom",
|
||||
confidence=round(conf, 2),
|
||||
label=tag_label_overrides.get(tag),
|
||||
))
|
||||
|
||||
return tags
|
||||
|
||||
|
||||
@@ -94,6 +94,21 @@ TAG_COLORS = {
|
||||
"open-source": "#3fb950",
|
||||
}
|
||||
|
||||
# Pick up colors for custom/auto-awarded tags defined in src/tag_rules.py so
|
||||
# adding a new tag there is a single-file change.
|
||||
def _merge_custom_tag_colors() -> None:
|
||||
try:
|
||||
from .. import tag_rules
|
||||
except Exception:
|
||||
return
|
||||
for tag_id, meta in tag_rules.TAG_DEFS.items():
|
||||
color = meta.get("color")
|
||||
if color and tag_id not in TAG_COLORS:
|
||||
TAG_COLORS[tag_id] = color
|
||||
|
||||
|
||||
_merge_custom_tag_colors()
|
||||
|
||||
GRADE_COLORS = {
|
||||
"S": "#ff6b9d",
|
||||
"A": "#3fb950",
|
||||
|
||||
@@ -11,6 +11,14 @@ _TAG_ACRONYMS = {"ml", "ai", "ui", "ux", "api", "cli", "sql", "css", "html", "js
|
||||
|
||||
|
||||
def _format_tag_label(tag: str) -> str:
|
||||
# Custom tags may define an explicit label in src/tag_rules.py::TAG_DEFS.
|
||||
try:
|
||||
from .. import tag_rules
|
||||
meta = tag_rules.TAG_DEFS.get(tag)
|
||||
if meta and meta.get("label"):
|
||||
return meta["label"]
|
||||
except Exception:
|
||||
pass
|
||||
return " ".join(
|
||||
w.upper() if w.lower() in _TAG_ACRONYMS else w.capitalize()
|
||||
for w in tag.split("-")
|
||||
@@ -74,7 +82,7 @@ def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dic
|
||||
|
||||
for tag in (data.tags or []):
|
||||
tag_color = TAG_COLORS.get(tag.tag, t["accent"])
|
||||
label = _format_tag_label(tag.tag)
|
||||
label = getattr(tag, "label", None) or _format_tag_label(tag.tag)
|
||||
tw = int(len(label) * 6.6 + 18)
|
||||
pill_opacity = 0.9 if tag.source == "earned" else 0.55
|
||||
|
||||
|
||||
Reference in New Issue
Block a user