feat: add one-click preview and deploy scripts
This commit is contained in:
+2
-1
@@ -5,7 +5,8 @@
|
||||
"scripts": {
|
||||
"build": "hexo generate",
|
||||
"clean": "hexo clean",
|
||||
"deploy": "hexo deploy",
|
||||
"preview": "bash scripts/blog.sh preview",
|
||||
"deploy": "bash scripts/blog.sh deploy",
|
||||
"server": "hexo server"
|
||||
},
|
||||
"hexo": {
|
||||
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
PORT="${PORT:-4000}"
|
||||
HOST="${HOST:-127.0.0.1}"
|
||||
BRANCH="${BRANCH:-main}"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
用法:
|
||||
./scripts/blog.sh preview # 一键预览环境
|
||||
./scripts/blog.sh deploy # 一键构建 + 提交 + 推送到自建 git
|
||||
|
||||
可选环境变量:
|
||||
PORT=4000 预览端口
|
||||
HOST=127.0.0.1 预览监听地址
|
||||
BRANCH=main 推送分支
|
||||
EOF
|
||||
}
|
||||
|
||||
preview() {
|
||||
echo "[preview] clean + start hexo server on ${HOST}:${PORT}"
|
||||
npx hexo clean
|
||||
exec npx hexo server -i "${HOST}" -p "${PORT}"
|
||||
}
|
||||
|
||||
deploy() {
|
||||
echo "[deploy] clean + generate"
|
||||
npx hexo clean
|
||||
npx hexo generate
|
||||
|
||||
echo "[deploy] git add"
|
||||
git add -A
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
echo "[deploy] 没有可提交的改动,跳过 commit/push"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if git diff --cached --quiet --ignore-submodules --exit-code; then
|
||||
: # keep shellcheck calm
|
||||
fi
|
||||
|
||||
if ! git rev-parse --verify HEAD >/dev/null 2>&1; then
|
||||
git commit -m "chore: deploy blog"
|
||||
else
|
||||
git commit -m "chore: deploy blog $(date '+%F %T')"
|
||||
fi
|
||||
|
||||
echo "[deploy] push origin ${BRANCH}"
|
||||
git push origin "${BRANCH}"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
preview) preview ;;
|
||||
deploy) deploy ;;
|
||||
-h|--help|help|"") usage ;;
|
||||
*)
|
||||
echo "未知命令: $1" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user