mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(widgets): attribution on every widget, and make it legible
Five of the seven standalone widgets and all three placeholder cards carried no attribution at all, and where it did render it was font-size 9 at opacity 0.5 (about 2.1:1 contrast) at the bottom of a 1500px card. Each embedded widget sits on a public profile and is the only organic acquisition surface we have. Shared helper so the styling can't drift again. font-size 10, opacity 0.75 (about 3.1:1), still using the theme's text_secondary so it stays roughly 4x fainter than the user's own content. Composite output is byte-identical in size; four standalone cards grow 16px where the footer would otherwise collide with existing content. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
This commit is contained in:
@@ -4,6 +4,7 @@ Uses the same card wrapper + theme system as real widgets so they look consisten
|
||||
"""
|
||||
from .themes.themes import THEMES
|
||||
from .utils.svg_helpers import card_wrapper, escape
|
||||
from .widgets.attribution import attribution_text
|
||||
|
||||
_MESSAGES = {
|
||||
"building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."),
|
||||
@@ -24,5 +25,8 @@ def render(variant: str, username: str, theme: str = "dark") -> str:
|
||||
f'font-size="18" font-weight="600" fill="{palette["text"]}">{escape(title)}</text>'
|
||||
f'<text x="24" y="82" font-family="-apple-system,Segoe UI,sans-serif" '
|
||||
f'font-size="13" fill="{palette["text_secondary"]}">{escape(subtitle)}</text>'
|
||||
# The card is 120 tall and the subtitle ends around y=85, so the
|
||||
# footer fits inside the existing bottom padding.
|
||||
+ attribution_text(palette, 200, 112, 0)
|
||||
)
|
||||
return card_wrapper(inner, width=400, height=120, theme=palette)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from ..models import AchievementData
|
||||
from ..themes import THEMES
|
||||
from ..utils import escape, card_wrapper
|
||||
from .attribution import FOOTER_H, attribution_text
|
||||
|
||||
|
||||
def _achievement_icon_svg(icon_type: str, color: str) -> str:
|
||||
@@ -69,5 +70,8 @@ def render_achievements_widget(
|
||||
font-size="10" fill="{t["text_secondary"]}">{escape(ach.subtitle)}{(" · " + escape(ach.event_date)) if ach.event_date else ""}</text>
|
||||
</g>'''
|
||||
|
||||
total_h = len(shown) * 56 + 50
|
||||
# The last achievement row leaves only 14px below it, so reserve
|
||||
# FOOTER_H for the attribution footer.
|
||||
total_h = len(shown) * 56 + 50 + FOOTER_H
|
||||
items += attribution_text(t, 190, total_h - 36 - 8)
|
||||
return card_wrapper(items, 380, total_h, t, "Achievements")
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Shared "Generated with gh-stats.com" footer for standalone widget SVGs.
|
||||
|
||||
Every widget served at /api/<u>/<widget>.svg carries this footer; keeping it
|
||||
in one place means all eight cards render it at the same size, opacity and
|
||||
offset from the card's bottom edge.
|
||||
"""
|
||||
|
||||
# Vertical space the footer needs at the bottom of a card. Widgets without
|
||||
# that much bottom padding already grow by it; composite.py reads the same
|
||||
# number back off data-gh-h to reclaim it when the widget is inlined.
|
||||
FOOTER_H = 16
|
||||
|
||||
|
||||
def attribution_text(theme: dict, x: float, y: float, reserved_h: int = FOOTER_H) -> str:
|
||||
"""Footer <text>, centered on x with its baseline at y.
|
||||
|
||||
data-gh-attribution marks it for composite.py to strip; data-gh-h says how
|
||||
much card height the composite reclaims along with it (0 when the footer
|
||||
sits inside padding the card already had).
|
||||
"""
|
||||
return f'''<text data-gh-attribution="1" data-gh-h="{reserved_h}"
|
||||
x="{x}" y="{y}" text-anchor="middle"
|
||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="10" fill="{theme["text_secondary"]}" opacity="0.75">Generated with gh-stats.com</text>'''
|
||||
@@ -3,6 +3,7 @@
|
||||
from ..models import CollaboratorData
|
||||
from ..themes import THEMES
|
||||
from ..utils import escape, card_wrapper, safe_color
|
||||
from .attribution import attribution_text
|
||||
|
||||
|
||||
def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str = "dark", settings: dict | None = None) -> str:
|
||||
@@ -49,4 +50,7 @@ def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str
|
||||
</g>'''
|
||||
|
||||
total_h = len(collabs[:max_count]) * 50 + 48
|
||||
# The rows already leave 26px of bottom padding, so the footer fits
|
||||
# inside it and the card height is unchanged (reserved height 0).
|
||||
items += attribution_text(t, 190, total_h - 36 - 8, 0)
|
||||
return card_wrapper(items, 380, total_h, t, "Top Collaborators")
|
||||
|
||||
@@ -127,5 +127,5 @@ def compose_widget(
|
||||
{embedded}
|
||||
<text x="{total_w // 2}" y="{total_h - 8}" text-anchor="middle"
|
||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="9" fill="{t["text_secondary"]}" opacity="0.5">Generated with gh-stats.com</text>
|
||||
font-size="10" fill="{t["text_secondary"]}" opacity="0.75">Generated with gh-stats.com</text>
|
||||
</svg>'''
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from ..models import FocusCategory
|
||||
from ..themes import THEMES, FOCUS_COLORS
|
||||
from ..utils import escape, card_wrapper
|
||||
from .attribution import FOOTER_H, attribution_text
|
||||
|
||||
|
||||
def render_focus_widget(categories: list[FocusCategory], theme_name: str = "dark", period: str = "1y", settings: dict | None = None) -> str:
|
||||
@@ -59,5 +60,8 @@ def render_focus_widget(categories: list[FocusCategory], theme_name: str = "dark
|
||||
<text x="16" y="{subtitle_y}" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="9" fill="{t["text_secondary"]}" opacity="0.7">Recent activity · {period_display}</text>'''
|
||||
|
||||
card_h = len(cats) * 36 + 54
|
||||
# The period subtitle leaves only 8px below it, so reserve FOOTER_H for
|
||||
# the attribution footer.
|
||||
card_h = len(cats) * 36 + 54 + FOOTER_H
|
||||
items += attribution_text(t, 190, card_h - 36 - 8)
|
||||
return card_wrapper(items, 380, card_h, t, "Recent Focus")
|
||||
|
||||
@@ -4,6 +4,7 @@ import math
|
||||
from ..models import GradeData
|
||||
from ..themes import THEMES, TAG_COLORS, GRADE_COLORS
|
||||
from ..utils import escape, card_wrapper, icon_svg
|
||||
from .attribution import FOOTER_H, attribution_text
|
||||
|
||||
# Tokens that should render uppercase instead of title-cased (e.g. "ml-engineer"
|
||||
# → "ML Engineer", not "Ml Engineer").
|
||||
@@ -132,7 +133,7 @@ def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dic
|
||||
# attribution. Matches the composite widget's footer convention so
|
||||
# the standalone grade widget feels visually consistent when it's
|
||||
# embedded on its own (the /api/<u>/grade.svg path).
|
||||
footer_h = 16
|
||||
footer_h = FOOTER_H
|
||||
card_h = (tags_y + tags_h + tag_padding) if data.tags else (stats_y + 54)
|
||||
card_h += footer_h
|
||||
|
||||
@@ -178,10 +179,6 @@ def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dic
|
||||
# card, so showing both would double-tag the same image.
|
||||
# Positioned in the inner-svg coordinate space (card_wrapper passes
|
||||
# title="" here, so inner is not vertically offset).
|
||||
inner += f'''
|
||||
<text data-gh-attribution="1" data-gh-h="{footer_h}"
|
||||
x="190" y="{card_h - 8}" text-anchor="middle"
|
||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="9" fill="{t["text_secondary"]}" opacity="0.5">Generated with gh-stats.com</text>'''
|
||||
inner += attribution_text(t, 190, card_h - 8, footer_h)
|
||||
|
||||
return card_wrapper(inner, 380, card_h, t, "")
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from ..models import ImpactWeek
|
||||
from ..themes import THEMES
|
||||
from ..utils import card_wrapper, safe_color
|
||||
from .attribution import FOOTER_H, attribution_text
|
||||
|
||||
|
||||
def render_impact_widget(weeks: list[ImpactWeek], theme_name: str = "dark", period: str = "6mo", settings: dict | None = None) -> str:
|
||||
@@ -14,7 +15,9 @@ def render_impact_widget(weeks: list[ImpactWeek], theme_name: str = "dark", peri
|
||||
t = THEMES[theme_name]
|
||||
s = settings or {}
|
||||
line_color = safe_color(s.get("line_color"), t["accent"])
|
||||
w, h = 380, 200
|
||||
# The summary block already ends ~12px above the card edge, which the
|
||||
# footer would sit on top of, so reserve FOOTER_H for it.
|
||||
w, h = 380, 200 + FOOTER_H
|
||||
chart_x, chart_y = 40, 8
|
||||
chart_w, chart_h = 316, 82
|
||||
|
||||
@@ -31,6 +34,7 @@ def render_impact_widget(weeks: list[ImpactWeek], theme_name: str = "dark", peri
|
||||
<text x="0" y="14" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="9" fill="{t["text_secondary"]}">commits over {period}</text>
|
||||
</g>'''
|
||||
inner += attribution_text(t, 190, h - 36 - 8)
|
||||
return card_wrapper(inner, w, h, t, "Impact Timeline")
|
||||
|
||||
max_commits = max((wk.commits for wk in weeks), default=1) or 1
|
||||
@@ -92,4 +96,6 @@ def render_impact_widget(weeks: list[ImpactWeek], theme_name: str = "dark", peri
|
||||
font-size="9" fill="{t["text_secondary"]}">commits over {period}</text>
|
||||
</g>'''
|
||||
|
||||
inner += attribution_text(t, 190, h - 36 - 8)
|
||||
|
||||
return card_wrapper(inner, w, h, t, "Impact Timeline")
|
||||
|
||||
@@ -4,6 +4,7 @@ import math
|
||||
from ..models import LanguageData
|
||||
from ..themes import THEMES, LANG_COLORS, FOCUS_COLORS
|
||||
from ..utils import escape, card_wrapper
|
||||
from .attribution import FOOTER_H, attribution_text
|
||||
|
||||
|
||||
def render_languages_widget(languages: list[LanguageData], theme_name: str = "dark", settings: dict | None = None) -> str:
|
||||
@@ -108,11 +109,7 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da
|
||||
# title="Languages", which adds a 36px translate to inner. The 36 is
|
||||
# already baked into the card height (rows_h + 36); the attribution
|
||||
# adds another 16 on top, positioned 8px from the bottom of the card.
|
||||
footer_h = 16
|
||||
footer_h = FOOTER_H
|
||||
card_h = rows_h + 36 + footer_h
|
||||
inner += f'''
|
||||
<text data-gh-attribution="1" data-gh-h="{footer_h}"
|
||||
x="190" y="{card_h - 36 - 8}" text-anchor="middle"
|
||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="9" fill="{t["text_secondary"]}" opacity="0.5">Generated with gh-stats.com</text>'''
|
||||
inner += attribution_text(t, 190, card_h - 36 - 8, footer_h)
|
||||
return card_wrapper(inner, 380, card_h, t, "Languages")
|
||||
|
||||
@@ -4,6 +4,7 @@ from datetime import date
|
||||
from ..models import StreakData
|
||||
from ..themes import THEMES
|
||||
from ..utils import escape, card_wrapper, safe_color
|
||||
from .attribution import FOOTER_H, attribution_text
|
||||
|
||||
|
||||
def _fmt_day(d: date, include_year: bool) -> str:
|
||||
@@ -59,7 +60,9 @@ def render_streaks_widget(
|
||||
current_color = safe_color(s.get("color"), t["accent"])
|
||||
max_color = t["text"]
|
||||
|
||||
width, height = 380, 170
|
||||
# The body already ends ~15px above the card edge, which the footer would
|
||||
# sit on top of, so reserve FOOTER_H for it.
|
||||
width, height = 380, 170 + FOOTER_H
|
||||
|
||||
# Inner content is translated 36px down by card_wrapper's title strip, so
|
||||
# every y below is measured from that inner origin.
|
||||
@@ -116,4 +119,6 @@ def render_streaks_widget(
|
||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||
font-size="10" fill="{t["text_secondary"]}">{escape(longest_caption)}</text>'''
|
||||
|
||||
inner += attribution_text(t, 190, height - 36 - 8)
|
||||
|
||||
return card_wrapper(inner, width, height, t, "Streaks")
|
||||
|
||||
Reference in New Issue
Block a user