From 769cde552d19fa90172baf9b6e45501de0eb4752 Mon Sep 17 00:00:00 2001 From: shay Date: Sat, 22 Aug 2026 16:10:26 -0700 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS --- generator/src/placeholder.py | 4 ++ generator/src/widgets/achievements.py | 6 +- generator/src/widgets/attribution.py | 24 +++++++ generator/src/widgets/collaborators.py | 4 ++ generator/src/widgets/composite.py | 2 +- generator/src/widgets/focus.py | 6 +- generator/src/widgets/grade.py | 9 +-- generator/src/widgets/impact.py | 8 ++- generator/src/widgets/languages.py | 9 +-- generator/src/widgets/streaks.py | 7 +- generator/tests/test_attribution.py | 94 ++++++++++++++++++++++++-- 11 files changed, 150 insertions(+), 23 deletions(-) create mode 100644 generator/src/widgets/attribution.py diff --git a/generator/src/placeholder.py b/generator/src/placeholder.py index 65c3e0d..5b60f25 100644 --- a/generator/src/placeholder.py +++ b/generator/src/placeholder.py @@ -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)}' f'{escape(subtitle)}' + # 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) diff --git a/generator/src/widgets/achievements.py b/generator/src/widgets/achievements.py index 0435564..1547e12 100644 --- a/generator/src/widgets/achievements.py +++ b/generator/src/widgets/achievements.py @@ -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 ""} ''' - 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") diff --git a/generator/src/widgets/attribution.py b/generator/src/widgets/attribution.py new file mode 100644 index 0000000..36806ab --- /dev/null +++ b/generator/src/widgets/attribution.py @@ -0,0 +1,24 @@ +"""Shared "Generated with gh-stats.com" footer for standalone widget SVGs. + +Every widget served at /api//.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 , 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'''Generated with gh-stats.com''' diff --git a/generator/src/widgets/collaborators.py b/generator/src/widgets/collaborators.py index 2526798..e3175f6 100644 --- a/generator/src/widgets/collaborators.py +++ b/generator/src/widgets/collaborators.py @@ -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 ''' 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") diff --git a/generator/src/widgets/composite.py b/generator/src/widgets/composite.py index b8636e7..349b8d2 100644 --- a/generator/src/widgets/composite.py +++ b/generator/src/widgets/composite.py @@ -127,5 +127,5 @@ def compose_widget( {embedded} Generated with gh-stats.com + font-size="10" fill="{t["text_secondary"]}" opacity="0.75">Generated with gh-stats.com ''' diff --git a/generator/src/widgets/focus.py b/generator/src/widgets/focus.py index 6382c18..f97a19b 100644 --- a/generator/src/widgets/focus.py +++ b/generator/src/widgets/focus.py @@ -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 Recent activity · {period_display}''' - 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") diff --git a/generator/src/widgets/grade.py b/generator/src/widgets/grade.py index 216d804..ebf6132 100644 --- a/generator/src/widgets/grade.py +++ b/generator/src/widgets/grade.py @@ -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//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''' - Generated with gh-stats.com''' + inner += attribution_text(t, 190, card_h - 8, footer_h) return card_wrapper(inner, 380, card_h, t, "") diff --git a/generator/src/widgets/impact.py b/generator/src/widgets/impact.py index d165547..546c52f 100644 --- a/generator/src/widgets/impact.py +++ b/generator/src/widgets/impact.py @@ -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 commits over {period} ''' + 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} ''' + inner += attribution_text(t, 190, h - 36 - 8) + return card_wrapper(inner, w, h, t, "Impact Timeline") diff --git a/generator/src/widgets/languages.py b/generator/src/widgets/languages.py index 00bb9a6..325c50b 100644 --- a/generator/src/widgets/languages.py +++ b/generator/src/widgets/languages.py @@ -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''' - Generated with gh-stats.com''' + inner += attribution_text(t, 190, card_h - 36 - 8, footer_h) return card_wrapper(inner, 380, card_h, t, "Languages") diff --git a/generator/src/widgets/streaks.py b/generator/src/widgets/streaks.py index 004a62f..e35ed9c 100644 --- a/generator/src/widgets/streaks.py +++ b/generator/src/widgets/streaks.py @@ -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)}''' + inner += attribution_text(t, 190, height - 36 - 8) + return card_wrapper(inner, width, height, t, "Streaks") diff --git a/generator/tests/test_attribution.py b/generator/tests/test_attribution.py index 95fb085..4563559 100644 --- a/generator/tests/test_attribution.py +++ b/generator/tests/test_attribution.py @@ -4,10 +4,29 @@ Standalone widget SVGs (served at /api//.svg) must show the "Generated with gh-stats.com" footer; the composite (served at /api/) must strip the per-widget footer and only show its own bottom one. """ -from src.models import GradeData, LanguageData, TagData +import xml.etree.ElementTree as ET + +import pytest + +from src import placeholder +from src.models import ( + AchievementData, + CollaboratorData, + FocusCategory, + GradeData, + ImpactWeek, + LanguageData, + StreakData, + TagData, +) from src.widgets import ( + render_achievements_widget, + render_collaborators_widget, + render_focus_widget, render_grade_widget, + render_impact_widget, render_languages_widget, + render_streaks_widget, compose_widget, ) @@ -28,16 +47,79 @@ def _languages_fixture() -> list[LanguageData]: ] -def test_standalone_grade_widget_has_attribution(): - svg = render_grade_widget(_grade_fixture(), theme_name="dark") +# Every widget reachable at /api//.svg, rendered from a minimal +# fixture. Parametrised so a new standalone widget can't ship without a footer. +_STANDALONE = { + "grade": lambda: render_grade_widget(_grade_fixture(), theme_name="dark"), + "languages": lambda: render_languages_widget(_languages_fixture(), theme_name="dark"), + "streaks": lambda: render_streaks_widget( + StreakData(current=5, max=12, current_start="2026-08-18", + last_active_date="2026-08-22", max_start="2026-01-01", + max_end="2026-01-12"), + theme_name="dark", + ), + "impact": lambda: render_impact_widget( + [ImpactWeek(week_start="2026-01-05", commits=7), + ImpactWeek(week_start="2026-01-12", commits=3)], + theme_name="dark", + ), + "impact_empty": lambda: render_impact_widget([], theme_name="dark"), + "focus": lambda: render_focus_widget( + [FocusCategory(category="Backend", percentage=70.0, commit_count=70), + FocusCategory(category="Docs", percentage=30.0, commit_count=30)], + theme_name="dark", + ), + "collaborators": lambda: render_collaborators_widget( + [CollaboratorData(username="bob", shared_repos=2, shared_commits=30)], + theme_name="dark", + ), + "achievements": lambda: render_achievements_widget( + [AchievementData(title="Hackathon win", subtitle="MIT", event_date="2026-03")], + theme_name="dark", + ), +} + + +@pytest.mark.parametrize("name", sorted(_STANDALONE)) +def test_standalone_widget_has_attribution(name): + svg = _STANDALONE[name]() assert "Generated with gh-stats.com" in svg assert 'data-gh-attribution="1"' in svg -def test_standalone_languages_widget_has_attribution(): - svg = render_languages_widget(_languages_fixture(), theme_name="dark") +@pytest.mark.parametrize("name", sorted(_STANDALONE)) +def test_standalone_widget_is_well_formed_svg(name): + ET.fromstring(_STANDALONE[name]()) + + +@pytest.mark.parametrize("name", sorted(_STANDALONE)) +def test_attribution_is_legible_and_consistent(name): + """The footer is a credit line, not a disclaimer: big enough to read, + faint enough to stay subordinate, and identical across every widget.""" + root = ET.fromstring(_STANDALONE[name]()) + nodes = [e for e in root.iter() if e.get("data-gh-attribution") == "1"] + assert len(nodes) == 1 + node = nodes[0] + assert node.get("font-size") == "10" + assert node.get("opacity") == "0.75" + assert node.get("text-anchor") == "middle" + + +@pytest.mark.parametrize("variant", ["building", "rate_limited", "not_found"]) +def test_placeholder_cards_have_attribution(variant): + svg = placeholder.render(variant, "alice", theme="dark") assert "Generated with gh-stats.com" in svg - assert 'data-gh-attribution="1"' in svg + ET.fromstring(svg) + + +def test_attribution_uses_theme_colors_not_hardcoded_hex(): + """The footer must pick up each theme's secondary text token.""" + from src.themes.themes import THEMES + + for theme_name in ("dark", "light"): + root = ET.fromstring(render_grade_widget(_grade_fixture(), theme_name=theme_name)) + node = next(e for e in root.iter() if e.get("data-gh-attribution") == "1") + assert node.get("fill") == THEMES[theme_name]["text_secondary"] def test_composite_strips_per_widget_attribution_from_grade():