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 .themes.themes import THEMES
|
||||||
from .utils.svg_helpers import card_wrapper, escape
|
from .utils.svg_helpers import card_wrapper, escape
|
||||||
|
from .widgets.attribution import attribution_text
|
||||||
|
|
||||||
_MESSAGES = {
|
_MESSAGES = {
|
||||||
"building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."),
|
"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'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'<text x="24" y="82" font-family="-apple-system,Segoe UI,sans-serif" '
|
||||||
f'font-size="13" fill="{palette["text_secondary"]}">{escape(subtitle)}</text>'
|
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)
|
return card_wrapper(inner, width=400, height=120, theme=palette)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from ..models import AchievementData
|
from ..models import AchievementData
|
||||||
from ..themes import THEMES
|
from ..themes import THEMES
|
||||||
from ..utils import escape, card_wrapper
|
from ..utils import escape, card_wrapper
|
||||||
|
from .attribution import FOOTER_H, attribution_text
|
||||||
|
|
||||||
|
|
||||||
def _achievement_icon_svg(icon_type: str, color: str) -> str:
|
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>
|
font-size="10" fill="{t["text_secondary"]}">{escape(ach.subtitle)}{(" · " + escape(ach.event_date)) if ach.event_date else ""}</text>
|
||||||
</g>'''
|
</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")
|
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 ..models import CollaboratorData
|
||||||
from ..themes import THEMES
|
from ..themes import THEMES
|
||||||
from ..utils import escape, card_wrapper, safe_color
|
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:
|
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>'''
|
</g>'''
|
||||||
|
|
||||||
total_h = len(collabs[:max_count]) * 50 + 48
|
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")
|
return card_wrapper(items, 380, total_h, t, "Top Collaborators")
|
||||||
|
|||||||
@@ -127,5 +127,5 @@ def compose_widget(
|
|||||||
{embedded}
|
{embedded}
|
||||||
<text x="{total_w // 2}" y="{total_h - 8}" text-anchor="middle"
|
<text x="{total_w // 2}" y="{total_h - 8}" text-anchor="middle"
|
||||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
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>'''
|
</svg>'''
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from ..models import FocusCategory
|
from ..models import FocusCategory
|
||||||
from ..themes import THEMES, FOCUS_COLORS
|
from ..themes import THEMES, FOCUS_COLORS
|
||||||
from ..utils import escape, card_wrapper
|
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:
|
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"
|
<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>'''
|
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")
|
return card_wrapper(items, 380, card_h, t, "Recent Focus")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import math
|
|||||||
from ..models import GradeData
|
from ..models import GradeData
|
||||||
from ..themes import THEMES, TAG_COLORS, GRADE_COLORS
|
from ..themes import THEMES, TAG_COLORS, GRADE_COLORS
|
||||||
from ..utils import escape, card_wrapper, icon_svg
|
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"
|
# Tokens that should render uppercase instead of title-cased (e.g. "ml-engineer"
|
||||||
# → "ML Engineer", not "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
|
# attribution. Matches the composite widget's footer convention so
|
||||||
# the standalone grade widget feels visually consistent when it's
|
# the standalone grade widget feels visually consistent when it's
|
||||||
# embedded on its own (the /api/<u>/grade.svg path).
|
# 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 = (tags_y + tags_h + tag_padding) if data.tags else (stats_y + 54)
|
||||||
card_h += footer_h
|
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.
|
# card, so showing both would double-tag the same image.
|
||||||
# Positioned in the inner-svg coordinate space (card_wrapper passes
|
# Positioned in the inner-svg coordinate space (card_wrapper passes
|
||||||
# title="" here, so inner is not vertically offset).
|
# title="" here, so inner is not vertically offset).
|
||||||
inner += f'''
|
inner += attribution_text(t, 190, card_h - 8, footer_h)
|
||||||
<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>'''
|
|
||||||
|
|
||||||
return card_wrapper(inner, 380, card_h, t, "")
|
return card_wrapper(inner, 380, card_h, t, "")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from ..models import ImpactWeek
|
from ..models import ImpactWeek
|
||||||
from ..themes import THEMES
|
from ..themes import THEMES
|
||||||
from ..utils import card_wrapper, safe_color
|
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:
|
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]
|
t = THEMES[theme_name]
|
||||||
s = settings or {}
|
s = settings or {}
|
||||||
line_color = safe_color(s.get("line_color"), t["accent"])
|
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_x, chart_y = 40, 8
|
||||||
chart_w, chart_h = 316, 82
|
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"
|
<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>
|
font-size="9" fill="{t["text_secondary"]}">commits over {period}</text>
|
||||||
</g>'''
|
</g>'''
|
||||||
|
inner += attribution_text(t, 190, h - 36 - 8)
|
||||||
return card_wrapper(inner, w, h, t, "Impact Timeline")
|
return card_wrapper(inner, w, h, t, "Impact Timeline")
|
||||||
|
|
||||||
max_commits = max((wk.commits for wk in weeks), default=1) or 1
|
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>
|
font-size="9" fill="{t["text_secondary"]}">commits over {period}</text>
|
||||||
</g>'''
|
</g>'''
|
||||||
|
|
||||||
|
inner += attribution_text(t, 190, h - 36 - 8)
|
||||||
|
|
||||||
return card_wrapper(inner, w, h, t, "Impact Timeline")
|
return card_wrapper(inner, w, h, t, "Impact Timeline")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import math
|
|||||||
from ..models import LanguageData
|
from ..models import LanguageData
|
||||||
from ..themes import THEMES, LANG_COLORS, FOCUS_COLORS
|
from ..themes import THEMES, LANG_COLORS, FOCUS_COLORS
|
||||||
from ..utils import escape, card_wrapper
|
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:
|
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
|
# title="Languages", which adds a 36px translate to inner. The 36 is
|
||||||
# already baked into the card height (rows_h + 36); the attribution
|
# already baked into the card height (rows_h + 36); the attribution
|
||||||
# adds another 16 on top, positioned 8px from the bottom of the card.
|
# 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
|
card_h = rows_h + 36 + footer_h
|
||||||
inner += f'''
|
inner += attribution_text(t, 190, card_h - 36 - 8, footer_h)
|
||||||
<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>'''
|
|
||||||
return card_wrapper(inner, 380, card_h, t, "Languages")
|
return card_wrapper(inner, 380, card_h, t, "Languages")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from datetime import date
|
|||||||
from ..models import StreakData
|
from ..models import StreakData
|
||||||
from ..themes import THEMES
|
from ..themes import THEMES
|
||||||
from ..utils import escape, card_wrapper, safe_color
|
from ..utils import escape, card_wrapper, safe_color
|
||||||
|
from .attribution import FOOTER_H, attribution_text
|
||||||
|
|
||||||
|
|
||||||
def _fmt_day(d: date, include_year: bool) -> str:
|
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"])
|
current_color = safe_color(s.get("color"), t["accent"])
|
||||||
max_color = t["text"]
|
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
|
# Inner content is translated 36px down by card_wrapper's title strip, so
|
||||||
# every y below is measured from that inner origin.
|
# 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-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||||
font-size="10" fill="{t["text_secondary"]}">{escape(longest_caption)}</text>'''
|
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")
|
return card_wrapper(inner, width, height, t, "Streaks")
|
||||||
|
|||||||
@@ -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>)
|
"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.
|
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 (
|
from src.widgets import (
|
||||||
|
render_achievements_widget,
|
||||||
|
render_collaborators_widget,
|
||||||
|
render_focus_widget,
|
||||||
render_grade_widget,
|
render_grade_widget,
|
||||||
|
render_impact_widget,
|
||||||
render_languages_widget,
|
render_languages_widget,
|
||||||
|
render_streaks_widget,
|
||||||
compose_widget,
|
compose_widget,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,16 +47,79 @@ def _languages_fixture() -> list[LanguageData]:
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_standalone_grade_widget_has_attribution():
|
# Every widget reachable at /api/<u>/<widget>.svg, rendered from a minimal
|
||||||
svg = render_grade_widget(_grade_fixture(), theme_name="dark")
|
# 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 "Generated with gh-stats.com" in svg
|
||||||
assert 'data-gh-attribution="1"' in svg
|
assert 'data-gh-attribution="1"' in svg
|
||||||
|
|
||||||
|
|
||||||
def test_standalone_languages_widget_has_attribution():
|
@pytest.mark.parametrize("name", sorted(_STANDALONE))
|
||||||
svg = render_languages_widget(_languages_fixture(), theme_name="dark")
|
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 "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():
|
def test_composite_strips_per_widget_attribution_from_grade():
|
||||||
|
|||||||
Reference in New Issue
Block a user