You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.4 KiB
31 lines
1.4 KiB
#!/usr/bin/env bash
|
|
# 由 index.template.html 生成可上传的 index.html:把 App 图标内联成 data URI。
|
|
#
|
|
# 为什么内联而不是放一个 icon.png 在旁边:这页只有一个文件要上传,
|
|
# 少一个文件就少一种「漏传了导致图标裂开」的失败形态,也少一次请求。
|
|
# 代价是 index.html 会大几十 KB —— 对一个要发 60MB 安装包的页面无所谓。
|
|
#
|
|
# App 图标换了就重跑本脚本,再把 index.html 传一次。
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
SRC="../../apps/client/assets/images/app_icon.png" # App 图标的唯一来源,与客户端同一份素材
|
|
SIZE=192 # 展示 92px,@2x 够用;再大只是徒增体积
|
|
|
|
[ -f "$SRC" ] || { echo "✗ 找不到 App 图标: $SRC" >&2; exit 1; }
|
|
|
|
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
|
sips -Z "$SIZE" "$SRC" --out "$TMP/icon.png" >/dev/null
|
|
B64="$(base64 -i "$TMP/icon.png" | tr -d '\n')"
|
|
|
|
# 用 python 替换:图标 base64 有几万字符,sed 在这个量级上会报 "RE error"
|
|
python3 - "$B64" <<'PY'
|
|
import sys
|
|
b64 = sys.argv[1]
|
|
src = open('index.template.html').read()
|
|
out = src.replace('__ICON_DATA_URI__', 'data:image/png;base64,' + b64)
|
|
assert '__ICON_DATA_URI__' not in out, '占位符没替换干净'
|
|
open('index.html', 'w').write(out)
|
|
PY
|
|
|
|
printf "✓ 已生成 index.html(%s KB)\n" "$(( $(stat -f%z index.html) / 1024 ))"
|
|
|