aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/serve-docs.sh
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2016-06-24 14:24:28 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-06-27 11:39:01 +0000
commitc19737c7f53cd93c3af896164947a9f5a077cd52 (patch)
tree514f90cd7c28f174625d6c7d9a18bd10008b3590 /scripts/serve-docs.sh
parent8fbde0f868aa9efe75ffd5af14dcdb5829e19b8d (diff)
Teach serve-docs.sh to generate a static web site.
-- Change-Id: Ic75d8f1d05b0ccba2faaad6527ab2719612325d8 Reviewed-on: https://bazel-review.googlesource.com/#/c/3892/ MOS_MIGRATED_REVID=125779082
Diffstat (limited to 'scripts/serve-docs.sh')
-rwxr-xr-xscripts/serve-docs.sh37
1 files changed, 35 insertions, 2 deletions
diff --git a/scripts/serve-docs.sh b/scripts/serve-docs.sh
index 6723682b4b..811fed7cbf 100755
--- a/scripts/serve-docs.sh
+++ b/scripts/serve-docs.sh
@@ -15,9 +15,30 @@
set -eu
-readonly PORT=${1-12345}
+if [ "${1-}" == "help" ]; then
+ cat <<EOF
+Usage:
+$0 [port]
+ Builds docs and starts a web server serving docs on localhost:port
+ Default port is 12345.
+$0 <target directory> [<serving prefix>]
+ Builds docs as static web pages in <target directory>.
+ Replaces absolute paths in the resulting HTML with <serving prefix>,
+ or, if it is not specified, with <target directory>.
+EOF
+ exit 0
+fi
+
+if [[ "${1-}" == [0-9]* ]]; then
+ readonly PORT=$1
+ readonly TARGET=''
+else
+ readonly PORT=${1-12345}
+ readonly TARGET=${1-}
+fi
readonly WORKING_DIR=$(mktemp -d)
+readonly SERVING_PREFIX=${2-$TARGET}
function check {
which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1)
@@ -29,7 +50,19 @@ function build_and_serve {
tar -xf bazel-genfiles/site/jekyll-tree.tar -C $WORKING_DIR
pkill -9 jekyll || true
- jekyll serve --detach --quiet --port $PORT --source $WORKING_DIR
+
+ if [ -z "$TARGET" ]; then
+ jekyll serve --detach --quiet --port $PORT --source $WORKING_DIR
+ else
+ TMP_TARGET=$(mktemp -d)
+ jekyll build --source $WORKING_DIR --destination "$TMP_TARGET"
+ REPLACEMENT=$(echo $SERVING_PREFIX | sed s/\\//\\\\\\//g)
+ find $TMP_TARGET -name '*.html' | xargs sed -i s/href=\\\"\\//href=\"$REPLACEMENT\\//g
+ find $TMP_TARGET -name '*.html' | xargs sed -i s/src=\\\"\\//src=\"$REPLACEMENT\\//g
+ cp -R $TMP_TARGET/* $TARGET
+ echo "Static pages copied to $TARGET"
+ echo "Should be served from $SERVING_PREFIX"
+ fi
}
function main {