forked from cotes2020/jekyll-theme-chirpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·109 lines (85 loc) · 1.72 KB
/
build.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
#
# Build jekyll site and store site files in ./_site
# © 2019 Cotes Chung
# Published under MIT License
CMD="JEKYLL_ENV=production bundle exec jekyll b"
DEST=$(realpath '_site')
help() {
echo "Usage:"
echo
echo " bash build.sh [options]"
echo
echo "Options:"
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
echo " -h, --help Print the help information"
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
}
init() {
set -eu
if [[ -d .container ]]; then
rm -rf .container
fi
if [[ -d _site ]]; then
jekyll clean
fi
temp=$(mktemp -d)
cp -r * $temp
cp -r .git $temp
mv $temp .container
}
check_unset() {
if [[ -z ${1:+unset} ]]
then
help
exit 1
fi
}
while [[ $# -gt 0 ]]
do
opt="$1"
case $opt in
-b|--baseurl)
check_unset $2
if [[ $2 == \/* ]]
then
CMD+=" -b $2"
else
help
exit 1
fi
shift
shift
;;
-d|--destination)
check_unset $2
DEST=$(realpath $2)
shift;
shift;
;;
-h|--help)
help
exit 0
;;
*) # unknown option
help
exit 1
;;
esac
done
init
cd .container
echo "$ cd $(pwd)"
python _scripts/py/init_all.py
CMD+=" -d ${DEST}"
echo "\$ $CMD"
eval $CMD
echo -e "\nBuild success, the site files placed in '${DEST}'."
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