-
Notifications
You must be signed in to change notification settings - Fork 512
/
Copy pathbuild_docs.sh
executable file
·92 lines (76 loc) · 2.43 KB
/
build_docs.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
#!/bin/bash
# run this script from the project root using `./scripts/build_docs.sh`
usage() {
echo "Usage: $0 [-b]"
echo ""
echo "Build Captum documentation."
echo ""
echo " -b Build static version of documentation (otherwise start server)"
echo ""
exit 1
}
BUILD_STATIC=false
while getopts 'hb' flag; do
case "${flag}" in
h)
usage
;;
b)
BUILD_STATIC=true
;;
*)
usage
;;
esac
done
echo "-----------------------------------"
echo "Generating API reference via Sphinx"
echo "-----------------------------------"
cd sphinx || exit
make html
cd .. || exit
echo "-----------------------------------"
echo "Building Captum Docusaurus site"
echo "-----------------------------------"
cd website || exit
yarn
# run script to parse html generated by sphinx
echo "--------------------------------------------"
echo "Parsing Sphinx docs and moving to Docusaurus"
echo "--------------------------------------------"
cd ..
mkdir -p "website/pages/api/"
cwd=$(pwd)
python scripts/parse_sphinx.py -i "${cwd}/sphinx/build/html/" -o "${cwd}/website/pages/api/"
SPHINX_JS_DIR='sphinx/build/html/_static/'
DOCUSAURUS_JS_DIR='website/static/js/'
mkdir -p $DOCUSAURUS_JS_DIR
# move JS files from /sphinx/build/html/_static/*:
cp "${SPHINX_JS_DIR}documentation_options.js" "${DOCUSAURUS_JS_DIR}documentation_options.js"
cp "${SPHINX_JS_DIR}jquery.js" "${DOCUSAURUS_JS_DIR}jquery.js"
cp "${SPHINX_JS_DIR}underscore.js" "${DOCUSAURUS_JS_DIR}underscore.js"
cp "${SPHINX_JS_DIR}doctools.js" "${DOCUSAURUS_JS_DIR}doctools.js"
cp "${SPHINX_JS_DIR}language_data.js" "${DOCUSAURUS_JS_DIR}language_data.js"
cp "${SPHINX_JS_DIR}searchtools.js" "${DOCUSAURUS_JS_DIR}searchtools.js"
# searchindex.js is not static util
cp "sphinx/build/html/searchindex.js" "${DOCUSAURUS_JS_DIR}searchindex.js"
# copy module sources
cp -r "sphinx/build/html/_sources/" "website/static/_sphinx-sources/"
echo "-----------------------------------"
echo "Generating tutorials"
echo "-----------------------------------"
mkdir -p "website/_tutorials"
mkdir -p "website/static/files"
python scripts/parse_tutorials.py -w "${cwd}"
cd website || exit
if [[ $BUILD_STATIC == true ]]; then
echo "-----------------------------------"
echo "Building static site"
echo "-----------------------------------"
yarn build
else
echo "-----------------------------------"
echo "Starting local server"
echo "-----------------------------------"
yarn start
fi