aboutsummaryrefslogtreecommitdiffstats
path: root/publish.sh
blob: 1ace2a47f32b37c3df168dfba17d436ecfcb98e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

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

commit_date=$(date +"%Y-%m-%d %H:%M:%S")
hugo --cleanDestinationDir --gc --minify
cd ~/blog/public || exit 1
git add .
git commit -m "auto update: $commit_date"
git push origin main

echo "部署完成!"