-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgenerate.sh
executable file
·62 lines (56 loc) · 1.75 KB
/
generate.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
#!/bin/sh
set -e
echo "*** Generate Webpages and Images ***"
python scripts/automate.py
echo ""
echo "*** Build With Jekyll ***"
# Use image that is a close to what is used for GitHub actions
export GITHUB_PAGES_IMAGE=ghcr.io/actions/jekyll-build-pages
export GITHUB_PAGES_VERSION=v1.0.13
docker run --rm \
-v "$PWD/docs:/srv/jekyll:Z" \
-w "/srv/jekyll" \
-e JEKYLL_ENV=development \
--entrypoint="" \
-it $GITHUB_PAGES_IMAGE:$GITHUB_PAGES_VERSION \
bash -c "rm -f Gemfile.lock && \
bundle install && \
chown $(id -u):$(id -g) Gemfile.lock && \
jekyll clean --config _config.yml && \
jekyll build -V --config _config.yml && \
chown -R $(id -u):$(id -g) _site"
echo ""
echo "*** Change Base URL For Generated Files ***"
LOCAL_URL=http://localhost:8000
find docs/_site -type f -name '*.html' -exec sed -i "s@https://sampleprograms\.io/@${LOCAL_URL}/@g" '{}' ';'
echo ""
echo "*** Start Webserver ***"
cd docs/_site
python -m http.server >/dev/null &
pid=$!
trap "printf '\n\n*** Kill webserver (PID %s) ***\n' $pid; \
trap - INT HUP ABRT TERM EXIT; \
(kill $pid || true); \
git checkout ../languages ../projects ../index.md; \
git clean -f ../languages ../projects" INT HUP ABRT TERM EXIT
sleep 5
echo ""
echo "*** Open Index ***"
echo "Press Ctrl+C to exit"
INDEX_URL="${LOCAL_URL}/index.html"
# Linux
if command -V xdg-open >/dev/null 2>&1
then
xdg-open "${INDEX_URL}"
# WSL2
elif command -V explorer.exe >/dev/null 2>&1
then
# Windows Explorer exits with invalid status
explorer.exe "${INDEX_URL}" || true
# Mac, if failed, give up!
elif !open "${INDEX_URL}" >/dev/null 2>&1
then
echo "Cannot open web browser."
echo "Please open ${INDEX_URL} in your web browser."
fi
sleep infinity