Skip to content

Commit 53ad698

Browse files
committed
Improved the assistant scripts.
1 parent e63e525 commit 53ad698

2 files changed

Lines changed: 25 additions & 27 deletions

File tree

build.sh

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Published under MIT License
66

77

8+
CMD="JEKYLL_ENV=production bundle exec jekyll b"
9+
DEST=$(realpath '_site')
10+
811
help() {
912
echo "Usage:"
1013
echo
@@ -25,18 +28,14 @@ init() {
2528
fi
2629

2730
if [[ -d _site ]]; then
28-
rm -rf _site
29-
fi
30-
31-
if [[ -d ../.chirpy-cache ]]; then
32-
rm -rf ../.chirpy-cache
31+
jekyll clean
3332
fi
3433

35-
mkdir ../.chirpy-cache
36-
cp -r * ../.chirpy-cache
37-
cp -r .git ../.chirpy-cache
34+
temp=$(mktemp -d)
35+
cp -r * $temp
36+
cp -r .git $temp
37+
mv $temp .container
3838

39-
mv ../.chirpy-cache .container
4039
}
4140

4241

@@ -49,9 +48,6 @@ check_unset() {
4948
}
5049

5150

52-
CMD="JEKYLL_ENV=production bundle exec jekyll b"
53-
DEST=`realpath "./_site"`
54-
5551
while [[ $# -gt 0 ]]
5652
do
5753
opt="$1"
@@ -72,10 +68,7 @@ do
7268
;;
7369
-d|--destination)
7470
check_unset $2
75-
if [[ -d $2 ]]; then
76-
rm -rf $2
77-
fi
78-
DEST=$2
71+
DEST=$(realpath $2)
7972
shift;
8073
shift;
8174
;;
@@ -90,17 +83,27 @@ do
9083
esac
9184
done
9285

86+
9387
init
9488

9589
cd .container
9690

9791
echo "$ cd $(pwd)"
9892
python _scripts/py/init_all.py
9993

100-
CMD+=" -d $DEST"
94+
CMD+=" -d ${DEST}"
10195
echo "\$ $CMD"
10296
eval $CMD
97+
echo -e "\nBuild success, the site files placed in '${DEST}'."
98+
99+
if [[ -d ${DEST}/.git ]]; then
100+
101+
if [[ ! -z $(git -C $DEST status -s) ]]; then
102+
git -C $DEST add .
103+
git -C $DEST commit -m "[Automation] Update site files." -q
104+
echo -e "\nPlease push the changes of '$(realpath $DEST)' to remote master branch.\n"
105+
fi
103106

104-
echo "$(date) - Build success, the Site files placed in _site."
107+
fi
105108

106109
cd .. && rm -rf .container

run.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,10 @@ init() {
3232
rm -rf .container
3333
fi
3434

35-
if [[ -d ../.chirpy-cache ]]; then
36-
rm -rf ../.chirpy-cache
37-
fi
38-
39-
mkdir ../.chirpy-cache
40-
cp -r * ../.chirpy-cache
41-
cp -r .git ../.chirpy-cache
42-
43-
mv ../.chirpy-cache .container
35+
temp=$(mktemp -d)
36+
cp -r * $temp
37+
cp -r .git $temp
38+
mv $temp .container
4439

4540
trap cleanup INT
4641
}

0 commit comments

Comments
 (0)