update at 2026-02-09 16:09:44

This commit is contained in:
douboer
2026-02-09 16:09:44 +08:00
parent ffb7367d3a
commit 917f210dae
20 changed files with 790 additions and 184 deletions

View File

@@ -3,7 +3,7 @@
"""
Font2SVG - fonts.json 生成脚本
扫描 frontend/public/fonts/ 目录,生成小程序所需的 fonts.json
扫描 fonts/ 目录,生成字体清单
URL 格式https://fonts.biboer.cn/fonts/{category}/{fontname}.ttf
"""
@@ -14,7 +14,7 @@ from urllib.parse import quote
# 配置
BASE_URL = "https://fonts.biboer.cn/fonts"
FONTS_DIR = Path(__file__).parent.parent / "frontend" / "public" / "fonts"
FONTS_DIR = Path(__file__).parent.parent / "fonts"
OUTPUT_FILE = Path(__file__).parent.parent / "frontend" / "public" / "fonts.json"
def scan_fonts(fonts_dir: Path) -> list:
@@ -51,9 +51,9 @@ def scan_fonts(fonts_dir: Path) -> list:
encoded_filename = quote(font_file.name)
url = f"{BASE_URL}/{encoded_category}/{encoded_filename}"
# 创建字体信息对象
# 创建字体信息对象id 在后续统一按序号回填)
font_info = {
"id": f"{category}/{font_name}",
"id": "",
"name": font_name,
"category": category,
"path": url,
@@ -71,7 +71,10 @@ def sort_fonts(fonts: list) -> list:
1. 按分类排序
2. 同分类内按名称排序
"""
return sorted(fonts, key=lambda x: (x["category"], x["name"]))
sorted_fonts = sorted(fonts, key=lambda x: (x["category"], x["name"]))
for index, font in enumerate(sorted_fonts, start=1):
font["id"] = f"{index:04d}"
return sorted_fonts
def save_fonts_json(fonts: list, output_file: Path):
"""