Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jan 28, 2024
1 parent 56ac168 commit b14aca0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField

from flask_babel import Babel
from flask_babel import lazy_gettext as _l
from flask_babel import Babel, lazy_gettext as _l
from babel.dates import format_date, get_timezone, get_timezone_name
import geoip2.database
import geoip2.errors
Expand All @@ -33,7 +32,7 @@ def get_timezone_from_ip():
response = reader.city(ip)
return response.location.time_zone
except geoip2.errors.AddressNotFoundError:
return request.headers.get("Time-Zone")
return request.headers.get("Time-Zone") or "UTC"


babel = Babel(
Expand All @@ -43,7 +42,7 @@ def get_timezone_from_ip():

@flask_app.before_request
def determine_locale_and_timezone():
"""根据IP获取时区"""
"""将语言和时区存入会话"""
session["locale"] = get_locale()
session["timezone"] = get_timezone_from_ip()

Expand Down Expand Up @@ -72,6 +71,7 @@ def index():
if not query_str:
selected_option = "" # 清空下拉列表选择项

# 获取翻译
if form.validate_on_submit():
translation = get_translation(query_str)
keys = [k for k in translation if is_valid_key(k)]
Expand Down
7 changes: 4 additions & 3 deletions extract_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
"""字体子集生成器"""

import json
from pathlib import Path
from fontTools import subset

P = Path(__file__).resolve().parent
from base import P, LANG_DIR

# 读取语言文件
with open(P / "lang" / "lzh.json", "r", encoding="utf-8") as file:
with open(LANG_DIR / "lzh.json", "r", encoding="utf-8") as file:
data = json.load(file)

# 提取字符串中包含的所有字符
all_char = {char for value in data.values() for char in str(value)}
all_char.discard("\n") # 去除换行符

# 输出路径
OUTPUT_PATH = str(P / "static" / "fonts" / "I.Ming-8.00.subset.woff2")
# 命令参数
args = [
"I.Ming-8.00.ttf",
f"--text={" ".join(all_char)}",
Expand Down

0 comments on commit b14aca0

Please sign in to comment.