From 3e260089d04a6242ee12846b6cefe7fd3827fd0f Mon Sep 17 00:00:00 2001 From: dongsk Date: Sat, 21 Nov 2026 17:41:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9D=99=E6=80=81=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E8=84=9A=E6=9C=AC=20Linux=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/export-static.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/export-static.sh b/scripts/export-static.sh index 9e70630..bff360a 100644 --- a/scripts/export-static.sh +++ b/scripts/export-static.sh @@ -26,15 +26,25 @@ VITEPRESS_BASE=./ pnpm docs:build echo "==> 2) 修复 Markdown 绝对图片路径" # guide/*.html 需要 ../media/,根目录 *.html 需要 ./media/ +fix_media_paths() { + local file="$1" prefix="$2" tmp + tmp="${file}.tmp" + sed \ + -e "s|src=\"/media/|src=\"${prefix}media/|g" \ + -e "s|href=\"/media/|href=\"${prefix}media/|g" \ + "$file" > "$tmp" + mv "$tmp" "$file" +} + if [ -d "$DIST/guide" ]; then for f in "$DIST"/guide/*.html; do [ -e "$f" ] || continue - sed -i '' 's|src="/media/|src="../media/|g; s|href="/media/|href="../media/|g' "$f" + fix_media_paths "$f" "../" done fi for f in "$DIST"/*.html; do [ -e "$f" ] || continue - sed -i '' 's|src="/media/|src="./media/|g; s|href="/media/|href="./media/|g' "$f" + fix_media_paths "$f" "./" done # 校验是否还有残留 @@ -89,6 +99,11 @@ if [[ "${1:-}" == "--pack" ]]; then echo "" echo "==> 4) 打包 dist-export.zip" rm -f "$ZIP" - (cd "$DIST" && zip -rq "$ZIP" . -x '*.DS_Store') + if command -v zip >/dev/null 2>&1; then + (cd "$DIST" && zip -rq "$ZIP" . -x '*.DS_Store') + else + # 兼容未安装 zip 命令的系统(macOS/Linux 均自带 Python 3) + (cd "$DIST" && python3 -m zipfile -c "$ZIP" .) + fi echo "✅ 打包完成:$ZIP ($(du -sh "$ZIP" | awk '{print $1}'))" fi