Skip to content

Commit ce577e9

Browse files
DavidMorganDavidMorgan
authored andcommitted
fix(profile): add horizontal padding to README typing banner
1 parent ca3410f commit ce577e9

5 files changed

Lines changed: 106 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
<a href="https://micromatrix.org">
1010
<picture>
11-
<source media="(prefers-color-scheme: dark)" srcset="https://readme-typing-svg.demolab.com?font=Source+Sans+3&amp;weight=600&amp;size=25&amp;duration=2400&amp;pause=1400&amp;background=000000&amp;vCenter=true&amp;width=900&amp;height=62&amp;lines=https%3A%2F%2Fmicromatrix.org;https%3A%2F%2Fblog.micromatrix.org&amp;color=FFE70B" />
12-
<source media="(prefers-color-scheme: light)" srcset="https://readme-typing-svg.demolab.com?font=Source+Sans+3&amp;weight=600&amp;size=25&amp;duration=2400&amp;pause=1400&amp;background=F6F8FA&amp;vCenter=true&amp;width=900&amp;height=62&amp;lines=https%3A%2F%2Fmicromatrix.org;https%3A%2F%2Fblog.micromatrix.org&amp;color=1F2328" />
13-
<img src="https://readme-typing-svg.demolab.com?font=Source+Sans+3&amp;weight=600&amp;size=25&amp;duration=2400&amp;pause=1400&amp;background=F6F8FA&amp;vCenter=true&amp;width=900&amp;height=62&amp;lines=https%3A%2F%2Fmicromatrix.org;https%3A%2F%2Fblog.micromatrix.org&amp;color=1F2328" alt="个人主页 micromatrix.org 与博客 blog.micromatrix.org" width="900" />
11+
<source media="(prefers-color-scheme: dark)" srcset="./assets/profile-typing-dark.svg" />
12+
<source media="(prefers-color-scheme: light)" srcset="./assets/profile-typing-light.svg" />
13+
<img src="./assets/profile-typing-light.svg" alt="个人主页 micromatrix.org 与博客 blog.micromatrix.org" width="900" />
1414
</picture>
1515
</a>
1616

‎assets/profile-typing-dark.svg‎

Lines changed: 31 additions & 0 deletions
Loading

‎assets/profile-typing-light.svg‎

Lines changed: 31 additions & 0 deletions
Loading

‎docs/PROFILE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## 页面与数据来源
77

88
- 顶部黄黑横幅:仓库中的 `assets/profile-header.svg`。
9-
- README 打字动画:[readme-typing-svg](https://github.com/DenverCoder1/readme-typing-svg),轮播主页与博客网址。
9+
- README 打字动画:[readme-typing-svg](https://github.com/DenverCoder1/readme-typing-svg),轮播主页与博客网址。图片保存在 `assets/profile-typing-*.svg`,左右各预留 24px;运行 `python3 scripts/update-profile-typing.py` 可重新生成。
1010
- 技术栈与网站徽章:[Shields.io](https://shields.io/)。
1111
- 统计与语言卡片:[GitHub Readme Stats Action](https://github.com/stats-organization/github-readme-stats-action)。旧的 `anuraghazra/github-readme-stats` 已停止维护,因此采用其推荐的后继生成器。
1212
- 成就奖杯:[GitHub Profile Trophy](https://github.com/ryo-ma/github-profile-trophy),固定到已核对的提交。

‎scripts/update-profile-typing.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Refresh the README typing SVGs with 24px of padding on both sides.
2+
3+
Run directly to fetch the upstream animations, or pass a directory containing
4+
light.svg and dark.svg to reuse previously downloaded animations.
5+
"""
6+
from pathlib import Path
7+
import sys
8+
from urllib.parse import urlencode
9+
from urllib.request import urlopen
10+
import xml.etree.ElementTree as ET
11+
12+
NS = "http://www.w3.org/2000/svg"
13+
ET.register_namespace("", NS)
14+
ET.register_namespace("xlink", "http://www.w3.org/1999/xlink")
15+
assets = Path(__file__).resolve().parents[1] / "assets"
16+
padding, width, height = 24, 900, 62
17+
18+
for theme, background, color in [("light", "F6F8FA", "1F2328"), ("dark", "000000", "FFE70B")]:
19+
options = {
20+
"font": "Source Sans 3", "weight": 600, "size": 25,
21+
"duration": 2400, "pause": 1400, "background": background,
22+
"vCenter": "true", "width": width - 2 * padding, "height": height,
23+
"lines": "https://micromatrix.org;https://blog.micromatrix.org", "color": color,
24+
}
25+
data = (Path(sys.argv[1]) / f"{theme}.svg").read_bytes() if len(sys.argv) > 1 else urlopen(
26+
"https://readme-typing-svg.demolab.com?" + urlencode(options), timeout=45,
27+
).read()
28+
animation = ET.fromstring(data)
29+
if animation.tag != f"{{{NS}}}svg":
30+
raise ValueError("Typing service did not return an SVG")
31+
animation.set("x", str(padding))
32+
animation.set("y", "0")
33+
frame = ET.Element(f"{{{NS}}}svg", {
34+
"width": str(width), "height": str(height), "viewBox": f"0 0 {width} {height}",
35+
})
36+
ET.SubElement(frame, f"{{{NS}}}rect", {"width": str(width), "height": str(height), "fill": f"#{background}"})
37+
frame.append(animation)
38+
target = assets / f"profile-typing-{theme}.svg"
39+
target.write_text(ET.tostring(frame, encoding="unicode") + "\n")
40+
print(f"Updated {target.name}")

0 commit comments

Comments
 (0)