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