diff --git a/generator/src/widgets/composite.py b/generator/src/widgets/composite.py index c831790..4687330 100644 --- a/generator/src/widgets/composite.py +++ b/generator/src/widgets/composite.py @@ -5,9 +5,23 @@ from ..themes import THEMES from ..utils import escape +_ATTRIBUTION_RE = re.compile( + r']*\bdata-gh-attribution="1"[^>]*>[^<]*', + re.DOTALL, +) +_ATTRIBUTION_H_RE = re.compile(r'\bdata-gh-h="(\d+)"') + + def _extract_inner(svg: str, widget_key: str) -> tuple[str, int]: """Extract the inner content from a widget SVG and rewrite IDs to be unique. + Also strips any per-widget "Generated with gh-stats" attribution text + (marked with data-gh-attribution="1") and shrinks the reported height + by data-gh-h so the composite doesn't reserve empty space for the + removed footer. The composite has its own attribution at the bottom + of the whole card; per-widget attributions are for the standalone + /api//.svg embed paths. + Returns (inner_svg_content, height). """ # Parse height @@ -31,6 +45,14 @@ def _extract_inner(svg: str, widget_key: str) -> tuple[str, int]: inner = re.sub(r']*>', '', inner, count=1) inner = re.sub(r'\s*$', '', inner) + # Strip any embedded attribution and reclaim its reserved height. + attr_match = _ATTRIBUTION_RE.search(inner) + if attr_match: + inner = inner.replace(attr_match.group(0), '', 1) + h_match = _ATTRIBUTION_H_RE.search(attr_match.group(0)) + if h_match: + h -= int(h_match.group(1)) + return inner, h diff --git a/generator/src/widgets/grade.py b/generator/src/widgets/grade.py index 96fc8be..74c89d3 100644 --- a/generator/src/widgets/grade.py +++ b/generator/src/widgets/grade.py @@ -172,11 +172,15 @@ def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dic {tags_svg} ''' - # Footer attribution. Positioned in the inner-svg coordinate space - # (card_wrapper passes title="" here, so inner is not vertically - # offset). 8px above the bottom edge mirrors the composite widget. + # Footer attribution. Marked with data-gh-attribution so composite.py + # can strip it (and reclaim the 16px) when this widget gets inlined + # — the composite has its own footer at the bottom of the whole + # 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''' diff --git a/generator/src/widgets/languages.py b/generator/src/widgets/languages.py index 1531b5b..01c8070 100644 --- a/generator/src/widgets/languages.py +++ b/generator/src/widgets/languages.py @@ -95,5 +95,19 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da {legend} ''' + # Footer attribution. Marked with data-gh-attribution so composite.py + # can strip it (and reclaim the 16px) when inlining the widget into + # the larger composite — the composite has its own footer, showing + # both would be visually redundant. card_wrapper here passes + # 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. rows_h = max(len(langs) * 22 + 40, 120) - return card_wrapper(inner, 380, rows_h + 36, t, "Languages") + footer_h = 16 + card_h = rows_h + 36 + footer_h + inner += f''' + Generated with gh-stats''' + return card_wrapper(inner, 380, card_h, t, "Languages")