diff --git a/.gitea/ci/render_stats_svgs.py b/.gitea/ci/render_stats_svgs.py
index 08a1f2b..47a6cd2 100644
--- a/.gitea/ci/render_stats_svgs.py
+++ b/.gitea/ci/render_stats_svgs.py
@@ -12,6 +12,9 @@ DEFAULT_TOTAL_COLOR = "#1f6feb"
DEFAULT_FILES_COLOR = "#2da44e"
DEFAULT_LANGUAGE_COUNT_COLOR = "#8250df"
TEXT_COLOR = "#ffffff"
+LIGHT_TEXT_COLOR = "#24292f"
+LIGHT_BADGE_BG = "#f6f8fa"
+LIGHT_BADGE_BORDER = "#d0d7de"
@dataclass
@@ -108,7 +111,7 @@ def parse_language_summary(path: Path) -> List[LanguageStat]:
return stats
-def badge_svg(label: str, message: str, color: str) -> str:
+def split_badge_svg(label: str, message: str, color: str) -> str:
height = 20
left_width = max(46, text_width(label))
right_width = max(46, text_width(message))
@@ -129,8 +132,35 @@ def badge_svg(label: str, message: str, color: str) -> str:
"""
-def write_badge(path: Path, label: str, message: str, color: str) -> None:
- path.write_text(badge_svg(label, message, color), encoding="utf-8")
+def flat_badge_svg(label: str, message: str, color: str) -> str:
+ height = 20
+ gap = 10
+ label_width = max(34, text_width(label) - 4)
+ message_width = max(38, text_width(message) - 4)
+ total_width = label_width + message_width + gap + 20
+ label_x = 10
+ message_x = label_x + label_width + gap
+ label_text_x = label_x + label_width / 2
+ message_text_x = message_x + message_width / 2
+
+ return f"""
+"""
+
+
+def write_badge(path: Path, label: str, message: str, color: str, variant: str = "split") -> None:
+ if variant == "flat":
+ svg = flat_badge_svg(label, message, color)
+ else:
+ svg = split_badge_svg(label, message, color)
+ path.write_text(svg, encoding="utf-8")
def render_readme(args: argparse.Namespace, languages: List[LanguageStat], badge_dir_name: str) -> str:
@@ -158,10 +188,6 @@ def render_readme(args: argparse.Namespace, languages: List[LanguageStat], badge
>
> 📅 更新时间: {args.updated_at}
-
-
-
-
## 📈 总体统计
| 统计项 | 数值 | 徽章 |
@@ -234,7 +260,13 @@ def main() -> None:
)
for stat in languages:
- write_badge(output_dir / f"{stat.lang_id}-lines.svg", stat.display_name, f"{stat.formatted_lines} 行", stat.color)
+ write_badge(
+ output_dir / f"{stat.lang_id}-lines.svg",
+ stat.display_name,
+ f"{stat.formatted_lines} 行",
+ stat.color,
+ variant="flat",
+ )
readme_path.write_text(render_readme(args, languages, badge_dir_name), encoding="utf-8")
diff --git a/tests/stats_svg_render_test.sh b/tests/stats_svg_render_test.sh
index 89d6dac..90dbcca 100644
--- a/tests/stats_svg_render_test.sh
+++ b/tests/stats_svg_render_test.sh
@@ -44,8 +44,12 @@ test -f "${readme_path}" || fail "renderer should create root README.md"
grep -q '