update at 2026-02-07 11:14:09
This commit is contained in:
50
scripts/copy-fonts.py
Normal file
50
scripts/copy-fonts.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
复制字体文件到 public/fonts 目录
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
def copy_fonts(source_dir='font', target_dir='frontend/public/fonts'):
|
||||
"""复制字体文件"""
|
||||
source_path = Path(source_dir)
|
||||
target_path = Path(target_dir)
|
||||
|
||||
if not source_path.exists():
|
||||
print(f"源目录不存在: {source_dir}")
|
||||
return
|
||||
|
||||
# 清空目标目录
|
||||
if target_path.exists():
|
||||
shutil.rmtree(target_path)
|
||||
|
||||
# 创建目标目录
|
||||
target_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
copied_count = 0
|
||||
|
||||
# 遍历所有子目录
|
||||
for category_dir in sorted(source_path.iterdir()):
|
||||
if not category_dir.is_dir():
|
||||
continue
|
||||
|
||||
category_name = category_dir.name
|
||||
category_target = target_path / category_name
|
||||
category_target.mkdir(exist_ok=True)
|
||||
|
||||
# 复制字体文件
|
||||
for font_file in sorted(category_dir.iterdir()):
|
||||
if font_file.suffix.lower() not in ['.ttf', '.otf']:
|
||||
continue
|
||||
|
||||
target_file = category_target / font_file.name
|
||||
shutil.copy2(font_file, target_file)
|
||||
copied_count += 1
|
||||
print(f"复制: {font_file} -> {target_file}")
|
||||
|
||||
print(f"\n总共复制了 {copied_count} 个字体文件到 {target_dir}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
copy_fonts()
|
||||
72
scripts/generate-font-list.py
Normal file
72
scripts/generate-font-list.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
生成字体清单 JSON 文件
|
||||
扫描 font/ 目录下的所有字体文件,生成一个 JSON 文件供前端使用
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
def scan_fonts(font_dir='font'):
|
||||
"""扫描字体目录,返回字体信息列表"""
|
||||
fonts = []
|
||||
font_dir_path = Path(font_dir)
|
||||
|
||||
if not font_dir_path.exists():
|
||||
print(f"字体目录不存在: {font_dir}")
|
||||
return fonts
|
||||
|
||||
# 遍历所有子目录
|
||||
for category_dir in sorted(font_dir_path.iterdir()):
|
||||
if not category_dir.is_dir():
|
||||
continue
|
||||
|
||||
category_name = category_dir.name
|
||||
|
||||
# 遍历类别下的所有字体文件
|
||||
for font_file in sorted(category_dir.iterdir()):
|
||||
if font_file.suffix.lower() not in ['.ttf', '.otf']:
|
||||
continue
|
||||
|
||||
# 生成字体信息
|
||||
font_info = {
|
||||
'id': f"{category_name}/{font_file.stem}",
|
||||
'name': font_file.stem,
|
||||
'filename': font_file.name,
|
||||
'category': category_name,
|
||||
'path': f"/fonts/{category_name}/{font_file.name}",
|
||||
}
|
||||
|
||||
fonts.append(font_info)
|
||||
|
||||
return fonts
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
# 扫描字体
|
||||
fonts = scan_fonts()
|
||||
|
||||
print(f"找到 {len(fonts)} 个字体文件")
|
||||
|
||||
# 保存到 JSON 文件
|
||||
output_file = 'frontend/public/fonts.json'
|
||||
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(fonts, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"字体清单已保存到: {output_file}")
|
||||
|
||||
# 统计信息
|
||||
categories = {}
|
||||
for font in fonts:
|
||||
category = font['category']
|
||||
categories[category] = categories.get(category, 0) + 1
|
||||
|
||||
print("\n按类别统计:")
|
||||
for category, count in sorted(categories.items()):
|
||||
print(f" {category}: {count} 个字体")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user