From f93ae55a1a47462bb43b1785b9e30731dc47c38c Mon Sep 17 00:00:00 2001 From: verdant Date: Sat, 25 Jul 2026 00:54:48 +0800 Subject: Add interactive confirmation before publishing --- publish.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'publish.sh') diff --git a/publish.sh b/publish.sh index 9c0be67..1ace2a4 100755 --- a/publish.sh +++ b/publish.sh @@ -1,10 +1,41 @@ #!/bin/bash -rm .hugo_build.lock +ask() { + local prompt="$1" + local answer + while true; do + read -p "$prompt (y/n) " answer + case "$answer" in + [Yy]* ) return 0;; + [Nn]* ) return 1;; + * ) echo "请输入 y 或 n";; + esac + done +} + +cd ~/blog/ || exit 1 + +echo "发布前确认:" +if ! ask "确认填写日期正确吗?"; then + echo "已取消发布。" + exit 0 +fi +if ! ask "确认文章标题正确吗?"; then + echo "已取消发布。" + exit 0 +fi +if ! ask "确认文章没有错别字了吗?"; then + echo "已取消发布。" + exit 0 +fi +if ! ask "确认没有发布草稿吗?"; then + echo "已取消发布。" + exit 0 +fi + +rm -f .hugo_build.lock -# 执行 Hugo 构建和部署 commit_date=$(date +"%Y-%m-%d %H:%M:%S") -cd ~/blog/ hugo --cleanDestinationDir --gc --minify cd ~/blog/public || exit 1 git add . -- cgit v1.2.3