-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·68 lines (63 loc) · 1.44 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
#!/bin/bash
HUGO_RUN=""
OPTS=""
BASE_URL="/"
IS_LIVE=""
IS_STATIC=""
PORT=1313
while [[ $# -gt 0 ]]; do
case $1 in
--verbose | --minify)
OPTS="$OPTS $1"
shift # past argument
;;
--live)
IS_LIVE="true"
shift # past argument
;;
--static)
IS_STATIC="true"
shift # past argument
;;
--baseURL)
BASE_URL="$2"
shift # past argument
shift # past value
;;
wc | eh)
if [[ ! -z "$IS_LIVE" ]]
then
echo "Preview $1"
mkdir -p config/_default/; cat content/navigation.md | ./navigation2menu.js > config/_default/menu.en.json
BASE_URL="http://localhost:$PORT/"
npx hugo server --config "config-$1.toml" --baseURL "$BASE_URL" $OPTS --port=$PORT &
sleep 3
echo "webserver running $1: http://localhost:$PORT/"
PORT=$((PORT+1))
else
echo "Building $1"
mkdir -p config/_default/; cat content/navigation.md | ./navigation2menu.js > config/_default/menu.en.json
npx hugo --config "config-$1.toml" --baseURL "$BASE_URL" $OPTS
fi
HUGO_RUN="true"
shift # past argument
;;
*)
echo "Unknown argument: $1"
shift # past argument
;;
esac
done
if [[ ! -z "$IS_LIVE" ]]
then
wait < <(jobs -p)
fi
if [[ ! -z "$IS_STATIC" ]]
then
npx http-server public
fi
if [[ -z "$HUGO_RUN" ]]
then
echo "No hugo config specified. Please specify wc or eh"
exit 1
fi