-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathupdateDocs.sh
executable file
·148 lines (119 loc) · 3.94 KB
/
updateDocs.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# vim: set ts=4 noet ai:
#
# [email protected] - 2020.11.16
# For more information on how this documentation is built using Sphinx,
# Read the Docs, and GitHub Actions/Pages, see:
#
# * https://tech.michaelaltfield.net/2020/07/18/sphinx-rtd-github-pages-1
# thank you Michael Altfield!
#
t=${1:-help}
if [ $t != 'all' -a $t != 'html' ]; then
cat << EOF
##############################################################################
File: $0
Purpose: A script that builds py4web documentation using Sphinx and updates
Pages. This script must be executed manually
Needs: A Linux system with the packages "rsync python3-sphinx
python3-sphinx-rtd-theme python3-stemmer
python3-git python3-pip python3-virtualenv python3-setuptools"
and the python3 modules "rinohtype pygments"
How to run: "$0 [all|html]" from inside the docs folder
##############################################################################
EOF
exit 0
fi
#####################
# DECLARE VARIABLES #
#####################
# go to py4web root folder
cwd=$(dirname -- "$( readlink -f -- "$0"; )")
cd $cwd/..
project_name=py4web
destination=apps/_documentation/static
# check for docs dir & sphinx config
if [ ! -e docs/conf.py ]; then
echo "$0: missing docs/conf.py" 1>&2
exit 1
fi
# check for _documentation app
if [ ! -e ${destination} ]; then
echo "$0: missing _documentation app" 1>&2
exit 1
fi
##############
# BUILD DOCS #
##############
# abort on nonzero exit status
set -o errexit
# cleanup old sphinx builds
rm -rf _build
languages='en '
# find other available languages (translations)
languages+=$(find docs/locales/ -mindepth 1 -maxdepth 1 -type d -exec basename \{\} \;)
# use a temp dir as docroot
docroot=$(mktemp -d)
for current_language in ${languages}; do
echo "Building for ${current_language}"
# make the current language available to conf.py
export current_language
# make HTML
# NOTE: this affect files in docs/locales/${current_language}/LC_MESSAGES/ sphinx-build -b html -D language="${current_language}" docs/ docs/_build/html/${current_language}
uv run --extra docs sphinx-build -b html -D language="${current_language}" docs/ docs/_build/html/${current_language}
mkdir -p "${docroot}/${current_language}"
base_target="${docroot}/${current_language}/${project_name}_${current_language}"
if [ $t = 'all' ]
then
# make PDF
uv run --extra docs sphinx-build -b rinoh -D language="${current_language}" docs/ docs/_build/rinoh
cp docs/_build/rinoh/target.pdf "${base_target}.pdf"
# make EPUB
uv run --extra docs sphinx-build -b epub -D language="${current_language}" docs/ docs/_build/epub
cp docs/_build/epub/target.epub "${base_target}.epub"
else
# HTML only, backup previous pdf and epub if any
target_pdf="${base_target}.pdf"
if [ -e "${target_pdf}" ]; then
cp "${target_pdf}" "${docroot}/${current_language}"
else
echo "WARNING: ${target_pdf} not found"
fi
target_epub="${base_target}.epub"
if [ -e "${target_epub}" ]; then
cp "${target_epub}" "${docroot}/${current_language}"
else
echo "WARNING: ${target_epub} not found"
fi
fi
# removes unuseful folders
rm -fr docs/_build/html/${current_language}/.doctrees
rm -fr docs/_build/html/${current_language}/_sources
# copy html files into docroot
rsync -a docs/_build/html/ ${docroot}
done
# copy favicon
favicon=apps/_scaffold/static/favicon.ico
cp ${favicon} ${docroot}
# final cleanup
rm -rf _build
# move docroot to destination
rm -fr ${destination}
#mv ${docroot} ${destination}
rsync -a "${docroot}/" ${destination} && rm -r ${docroot}
################
# CUSTOM INDEX #
################
echo "Writing ${destination}/index.html"
cat > ${destination}/index.html <<EOF
<!DOCTYPE html>
<html>
<head>
<title>${project_name} Docs</title>
<meta http-equiv = "refresh" content="0; url='en/index.html'" />
</head>
<body>
<p>Please wait while you're redirected to our documentation.</p>
</body>
</html>
EOF