forked from cotes2020/jekyll-theme-chirpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·133 lines (110 loc) · 2.52 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·133 lines (110 loc) · 2.52 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#
# Build jekyll site and store site files in ./_site
# v2.0
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2019 Cotes Chung
# Published under MIT License
set -eu
CMD="JEKYLL_ENV=production bundle exec jekyll b"
WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
CONTAINER="${WORK_DIR}/.container"
DEST="${WORK_DIR}/_site"
docker=false
_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)"
echo " --docker Build site within docker"
}
_install_tools() {
# docker image `jekyll/jekyll` based on Alpine Linux
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
apk update
apk add yq
}
_init() {
cd "$WORK_DIR"
if [[ -f Gemfile.lock ]]; then
rm -f Gemfile.lock
fi
if [[ -d $CONTAINER ]]; then
rm -rf "$CONTAINER"
fi
if [[ -d $DEST ]]; then
bundle exec jekyll clean
fi
local _temp="$(mktemp -d)"
cp -r ./* "$_temp"
cp -r ./.git "$_temp"
mv "$_temp" "$CONTAINER"
}
_build() {
cd "$CONTAINER"
echo "$ cd $(pwd)"
bash "_scripts/sh/create_pages.sh"
bash "_scripts/sh/dump_lastmod.sh"
CMD+=" -d $DEST"
echo "\$ $CMD"
eval "$CMD"
echo -e "\nBuild success, the site files have been placed in '${DEST}'."
if [[ -d "${DEST}/.git" ]]; then
if [[ -n $(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 $DEST to remote master branch.\n"
fi
fi
cd .. && rm -rf "$CONTAINER"
}
_check_unset() {
if [[ -z ${1:+unset} ]]; then
_help
exit 1
fi
}
main() {
while [[ $# -gt 0 ]]; do
opt="$1"
case $opt in
-b | --baseurl)
local _baseurl="$2"
if [[ -z $_baseurl ]]; then
_baseurl='""'
fi
CMD+=" -b $_baseurl"
shift
shift
;;
-d | --destination)
_check_unset "$2"
DEST="$(realpath "$2")"
shift
shift
;;
--docker)
docker=true
shift
;;
-h | --help)
_help
exit 0
;;
*) # unknown option
_help
exit 1
;;
esac
done
if $docker; then
_install_tools
fi
_init
_build
}
main "$@"