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,10 +4,29 @@ Standalone widget SVGs (served at /api/<u>/<widget>.svg) must show the
|
||||
"Generated with gh-stats.com" footer; the composite (served at /api/<u>)
|
||||
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/<u>/<widget>.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():
|
||||
|
||||
Reference in New Issue
Block a user