Align Douyin nav icons with WeChat: PNG export and relative paths for real devices.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4fd2e574c1
commit
bcbf54ce76
@ -4,6 +4,7 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { spawnSync } from 'child_process'
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const out = 'dist'
|
||||
@ -49,11 +50,44 @@ function stripMaps(dir) {
|
||||
return n
|
||||
}
|
||||
|
||||
/** 真机兼容:webp → png(保留原 webp) */
|
||||
function convertIconsWebpToPng(iconsDir) {
|
||||
if (!fs.existsSync(iconsDir)) return 0
|
||||
const py = `
|
||||
from pathlib import Path
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
raise SystemExit(2)
|
||||
root = Path(r'''${iconsDir.replace(/\\/g, '/')}''')
|
||||
n = 0
|
||||
for src in root.glob('*.webp'):
|
||||
dst = src.with_suffix('.png')
|
||||
im = Image.open(src)
|
||||
if im.mode not in ('RGB', 'RGBA'):
|
||||
im = im.convert('RGBA')
|
||||
im.save(dst, format='PNG', optimize=True)
|
||||
n += 1
|
||||
print(n)
|
||||
`
|
||||
const r = spawnSync('python', ['-c', py], { encoding: 'utf8' })
|
||||
if (r.status === 2) {
|
||||
console.warn('[copy-static] Pillow missing — skip webp→png')
|
||||
return 0
|
||||
}
|
||||
if (r.status !== 0) {
|
||||
console.warn('[copy-static] webp→png failed:', r.stderr || r.stdout)
|
||||
return 0
|
||||
}
|
||||
return Number((r.stdout || '').trim()) || 0
|
||||
}
|
||||
|
||||
const icons = copyDir(
|
||||
path.join(root, 'src/public/icons'),
|
||||
path.join(root, out, 'icons'),
|
||||
{ wipe: true },
|
||||
)
|
||||
const pngs = convertIconsWebpToPng(path.join(root, out, 'icons'))
|
||||
const assets = copyDir(
|
||||
path.join(root, 'src/assets'),
|
||||
path.join(root, out, 'assets'),
|
||||
@ -66,5 +100,5 @@ const bookImgs = copyDir(
|
||||
)
|
||||
const maps = stripMaps(path.join(root, out))
|
||||
console.log(
|
||||
`[copy-static] ${out}: icons=${icons} assets=${assets} bookImgs=${bookImgs} mapsRemoved=${maps}`,
|
||||
`[copy-static] ${out}: icons=${icons} png=${pngs} assets=${assets} bookImgs=${bookImgs} mapsRemoved=${maps}`,
|
||||
)
|
||||
|
||||
@ -48,9 +48,12 @@ function countLinks(cat: NavCategory) {
|
||||
|
||||
function iconSrc(icon: string) {
|
||||
if (!icon) return ''
|
||||
// 必须从小程序包根读:/icons/xxx.webp(去掉 / 会变成相对 pages/nav/,全裂)
|
||||
const cleaned = icon.replace(/^\//, '')
|
||||
return `/icons/${cleaned.replace(/^icons\//, '')}`
|
||||
// 真机:绝对路径 /icons 偶发失败;相对 pages/nav → ../../icons
|
||||
// 真机对本地 webp 常空白 → 统一 png(copy-static 已从 webp 导出)
|
||||
const cleaned = icon.replace(/^\//, '').replace(/^icons\//, '')
|
||||
const base = cleaned.replace(/\.(webp|png|jpe?g)$/i, '')
|
||||
if (process.env.TARO_ENV === 'h5') return `/icons/${base}.png`
|
||||
return `../../icons/${base}.png`
|
||||
}
|
||||
|
||||
const MENU_SVG = (open: boolean) =>
|
||||
@ -276,7 +279,7 @@ function NavPageInner() {
|
||||
{isH5 ? (
|
||||
<H5Box html={LOGO_SVG} />
|
||||
) : (
|
||||
<Image className="hub-logo-img" src="/icons/nomadro.webp" mode="aspectFit" />
|
||||
<Image className="hub-logo-img" src={iconSrc('/icons/nomadro.webp')} mode="aspectFit" />
|
||||
)}
|
||||
<H5Txt className="nav-portal-brand">nomadro</H5Txt>
|
||||
<H5Txt className="nav-portal-sep">·</H5Txt>
|
||||
@ -300,7 +303,7 @@ function NavPageInner() {
|
||||
|
||||
<H5Box className="desktop-rail">
|
||||
<H5Box className="desktop-rail-brand">
|
||||
<Image src="/icons/_brand.webp" className="desktop-rail-brand-img" mode="aspectFit" />
|
||||
<Image src={iconSrc('/icons/_brand.webp')} className="desktop-rail-brand-img" mode="aspectFit" />
|
||||
<H5Box>
|
||||
<H5Txt className="desktop-rail-title">{nav.brand}</H5Txt>
|
||||
<H5Txt className="desktop-rail-sub">{nav.tagline}</H5Txt>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user