forked from Vbaethon/HOMOMIX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_readme.py
72 lines (45 loc) · 1.98 KB
/
generate_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
icon_dir = 'Icon/Color/'
readme_file = 'README.md'
start_marker = '<!--start-icons-->'
end_marker = '<!--end-icons-->'
html_header = f'\n\n{start_marker}\n\n## 图标展示\n\n'
html_content = '<table style="width: 100%; text-align: center;"><tr>'
columns = 7
col_count = 0
icon_files = [f for f in os.listdir(icon_dir) if f.endswith(('.png', '.jpg', '.jpeg', '.svg'))]
icon_files_sorted = sorted(icon_files, key=lambda x: os.path.splitext(x)[0].lower())
for icon_file in icon_files_sorted:
icon_path = os.path.join(icon_dir, icon_file)
name_without_extension = os.path.splitext(icon_file)[0]
if len(name_without_extension) > 10:
name_display = name_without_extension[:10] + '...'
else:
name_display = name_without_extension
print(f"Processing icon: {icon_file} -> Display name: {name_display}") # 调试输出
html_content += f'''
<td align="center" style="padding: 10px;">
<img src="{icon_path}" alt="{icon_file}" width="60" height="60"><br>
<span style="font-size: 8px;">{name_display}</span>
</td>'''
col_count += 1
if col_count % columns == 0:
html_content += '</tr><tr>'
html_content += '</tr></table>'
html_footer = f'\n\n{end_marker}\n\n'
with open(readme_file, 'r') as f:
readme_content = f.read()
start_idx = readme_content.find(start_marker)
end_idx = readme_content.find(end_marker)
if start_idx != -1 and end_idx != -1:
new_readme_content = (
readme_content[:start_idx + len(start_marker)] +
'\n\n' + html_content + '\n\n' +
readme_content[end_idx:]
)
else:
# 如果没有找到标记,默认将新表格插入到文档末尾
new_readme_content = readme_content + '\n\n' + start_marker + '\n\n' + html_content + '\n\n' + end_marker + '\n\n'
with open(readme_file, 'w') as f:
f.write(new_readme_content)
print("图标表格已成功更新到 README.md 文件。")