Improved the assistant scripts.

This commit is contained in:
Cotes Chung 2019-10-01 03:38:36 +08:00
parent 9913da88cc
commit a76e41a5dc
2 changed files with 25 additions and 27 deletions

View file

@ -5,6 +5,9 @@
# Published under MIT License # Published under MIT License
CMD="JEKYLL_ENV=production bundle exec jekyll b"
DEST=$(realpath '_site')
help() { help() {
echo "Usage:" echo "Usage:"
echo echo
@ -25,18 +28,14 @@ init() {
fi fi
if [[ -d _site ]]; then if [[ -d _site ]]; then
rm -rf _site jekyll clean
fi fi
if [[ -d ../.chirpy-cache ]]; then temp=$(mktemp -d)
rm -rf ../.chirpy-cache cp -r * $temp
fi cp -r .git $temp
mv $temp .container
mkdir ../.chirpy-cache
cp -r * ../.chirpy-cache
cp -r .git ../.chirpy-cache
mv ../.chirpy-cache .container
} }
@ -49,9 +48,6 @@ check_unset() {
} }
CMD="JEKYLL_ENV=production bundle exec jekyll b"
DEST=`realpath "./_site"`
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
opt="$1" opt="$1"
@ -72,10 +68,7 @@ do
;; ;;
-d|--destination) -d|--destination)
check_unset $2 check_unset $2
if [[ -d $2 ]]; then DEST=$(realpath $2)
rm -rf $2
fi
DEST=$2
shift; shift;
shift; shift;
;; ;;
@ -90,6 +83,7 @@ do
esac esac
done done
init init
cd .container cd .container
@ -97,10 +91,19 @@ cd .container
echo "$ cd $(pwd)" echo "$ cd $(pwd)"
python _scripts/py/init_all.py python _scripts/py/init_all.py
CMD+=" -d $DEST" CMD+=" -d ${DEST}"
echo "\$ $CMD" echo "\$ $CMD"
eval $CMD eval $CMD
echo -e "\nBuild success, the site files placed in '${DEST}'."
echo "$(date) - Build success, the Site files placed in _site." if [[ -d ${DEST}/.git ]]; then
if [[ ! -z $(git -C $DEST status -s) ]]; then
git -C $DEST add .
git -C $DEST commit -m "[Automation] Update site files." -q
echo -e "\nPlease push the changes of '$(realpath $DEST)' to remote master branch.\n"
fi
fi
cd .. && rm -rf .container cd .. && rm -rf .container

13
run.sh
View file

@ -32,15 +32,10 @@ init() {
rm -rf .container rm -rf .container
fi fi
if [[ -d ../.chirpy-cache ]]; then temp=$(mktemp -d)
rm -rf ../.chirpy-cache cp -r * $temp
fi cp -r .git $temp
mv $temp .container
mkdir ../.chirpy-cache
cp -r * ../.chirpy-cache
cp -r .git ../.chirpy-cache
mv ../.chirpy-cache .container
trap cleanup INT trap cleanup INT
} }