Last active
February 13, 2024 13:56
-
-
Save du33169/b5a1dc93fd51dd095ba86070881385aa to your computer and use it in GitHub Desktop.
Hugo deploy generated public fold to git repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: put under hugo site source root, fill the params, and run the script in linux shell | |
# What does it do: call hugo, update public to target git folder, git add,commit and push | |
###############[params]################# | |
repo='' | |
src=public | |
target=.DeployPublic | |
branch=master | |
######################################## | |
# set -x # display command | |
rm -rf $src | |
hugo --gc --minify | |
if [ $? -eq 0 ] && [ -d "$src" ]; then | |
if [ ! -d "$target" ]; then | |
mkdir $target | |
cd $target | |
git init --initial-branch=$branch | |
git remote add origin $repo | |
git pull origin $branch | |
cd .. | |
PUSH_ARG="-u" | |
fi | |
rsync -a --delete $src/ $target --exclude=".*" -q # the slash '/' is necessary | |
#copy validify | |
tgtCnt=$(ls $target -1|wc -l) | |
srcCnt=$(ls $src -1 | wc -l) | |
if [ $srcCnt = $tgtCnt ];then | |
cd $target | |
echo "Entered $(pwd)" | |
git status | |
while true; do | |
read -r -p "Deploy? [y/n] " input | |
case $input in | |
[yY][eE][sS]|[yY]) | |
break | |
;; | |
[nN][oO]|[nN]) | |
exit | |
break | |
;; | |
*) | |
echo "Invalid input..." | |
;; | |
esac | |
done | |
git add . | |
git commit -m "$(date)" | |
git push origin $branch $PUSH_ARG | |
else | |
echo "FATAL: copy item count mismatch, expect $tgtCnt, got $curCnt" | |
fi | |
cd .. | |
else | |
echo "FATAL: build failed or $src not exist" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment