🎨 refine(stats): simplify summary and badge colors
Ubuntu System Information / show-system-info (push) Successful in 1s
Details
Ubuntu System Information / show-system-info (push) Successful in 1s
Details
This commit is contained in:
parent
1259495cbb
commit
6552f8be47
|
|
@ -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"""<svg xmlns="http://www.w3.org/2000/svg" width="{total_width}" height="{height}" role="img" aria-label="{escape_xml(label)}: {escape_xml(message)}">
|
||||
<title>{escape_xml(label)}: {escape_xml(message)}</title>
|
||||
<rect width="{total_width}" height="{height}" rx="10" fill="{LIGHT_BADGE_BG}" stroke="{LIGHT_BADGE_BORDER}" />
|
||||
<rect x="{message_x}" y="3" width="{message_width}" height="14" rx="7" fill="{escape_xml(color)}" />
|
||||
<g text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||
<text x="{label_text_x:.1f}" y="14" fill="{LIGHT_TEXT_COLOR}">{escape_xml(label)}</text>
|
||||
<text x="{message_text_x:.1f}" y="14" fill="{TEXT_COLOR}">{escape_xml(message)}</text>
|
||||
</g>
|
||||
</svg>
|
||||
"""
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,12 @@ test -f "${readme_path}" || fail "renderer should create root README.md"
|
|||
grep -q '<svg' "${output_dir}/total-lines.svg" || fail "svg badges should contain svg markup"
|
||||
grep -q '2,120' "${output_dir}/total-lines.svg" || fail "total-lines badge should include formatted total code"
|
||||
grep -q 'Python' "${output_dir}/python-lines.svg" || fail "language badge should include display name"
|
||||
! grep -q 'fill="#555555"' "${output_dir}/python-lines.svg" || fail "language badge should not use the heavy gray label background"
|
||||
grep -q '\./badges/total-lines.svg' "${readme_path}" || fail "README should reference badges via relative svg paths"
|
||||
grep -q '\./badges/python-lines.svg' "${readme_path}" || fail "README should reference language badges via relative svg paths"
|
||||
! grep -q '^!\[总代码\](\./badges/total-lines.svg)$' "${readme_path}" || fail "README should not duplicate summary badges above the table"
|
||||
! grep -q '^!\[总文件\](\./badges/total-files.svg)$' "${readme_path}" || fail "README should not duplicate summary badges above the table"
|
||||
! grep -q '^!\[语言种类\](\./badges/language-count.svg)$' "${readme_path}" || fail "README should not duplicate summary badges above the table"
|
||||
grep -q 'Gitea Actions' "${readme_path}" || fail "README should mention Gitea Actions"
|
||||
grep -q '此分支由 Gitea Actions 自动生成和维护' "${readme_path}" || fail "README should explain that stats branch is generated"
|
||||
grep -q '请勿手动修改此分支的内容' "${readme_path}" || fail "README should warn against manual edits"
|
||||
|
|
|
|||
Loading…
Reference in New Issue