forked from Oreoxmt/pingcap-docs-website-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·60 lines (45 loc) · 1.21 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
#!/bin/bash
set -e
FIND=$(which gfind || which find)
SED=$(which gsed || which sed)
replace_image_path() {
( cd markdown-pages
$FIND . -maxdepth 3 -mindepth 3 | while IFS= read -r DIR; do
DIR="${DIR#./}"
PREFIX="$(dirname "$DIR")"
$FIND "$DIR" -name '*.md' | while IFS= read -r FILE; do
$SED -r -i "s~]\(/media(/$PREFIX)?~](/media/$PREFIX~g" "$FILE"
done
done
)
}
move_images() {
( cd markdown-pages
$FIND . -maxdepth 3 -mindepth 3 | while IFS= read -r DIR; do
PREFIX="$(dirname "$DIR")"
if [ -d "$PREFIX/master/media" ]; then
mkdir -p "../website-docs/public/media/$PREFIX"
cp -r "$PREFIX/master/media/." "../website-docs/public/media/$PREFIX"
fi
done
)
}
CMD=build
if [ "$1" == "develop" ] || [ "$1" == "dev" ]; then
CMD=start
fi
if [ ! -e website-docs/.git ]; then
git clone https://github.com/pingcap/website-docs
fi
if [ ! -e website-docs/docs/markdown-pages ]; then
ln -s ../../markdown-pages website-docs/docs/markdown-pages
fi
cp docs.json website-docs/docs/docs.json
if [ "$CMD" == "start" ]; then
(cd website-docs && yarn && yarn start)
fi
if [ "$CMD" == "build" ]; then
replace_image_path
(cd website-docs && yarn && yarn build)
move_images
fi