Skip to content

Instantly share code, notes, and snippets.

@mhaberler
Last active June 27, 2016 19:27
Show Gist options
  • Save mhaberler/ede68eae275c38a5364734c065a1b9c0 to your computer and use it in GitHub Desktop.
Save mhaberler/ede68eae275c38a5364734c065a1b9c0 to your computer and use it in GitHub Desktop.
running jekyll-asciidoctor with LiveReload on change

The machinekit.io website is formatted with the docker-jekyll-asciidoctor docker image.

to run this locally "at home":

  • install docker - see https://docs.docker.com/engine/installation/linux/debian/
  • pull the image from dockerhub: docker pull haberlerm/docker-jekyll-asciidoctor
  • review and run the serve.sh script in the toplevel directory of your website
  • review the values in config_preview.yml which were generated by the first run
  • run serve.sh again, let it run to completion for the initial format of the whole site which can take 10-15mins
  • stop serve.sh with ^C and run it again, it will start with --incremental --skip-initial-build for quick startup since the _site directory already exists
  • point the browser to this server at http://<ip>:4000

The serve.sh script includes support for LiveReload - any change to an asciidoc should cause an automatic browser reload after a few seconds displaying the new content as soon as formatting finishes. There is no LiveReload browser plugin needed - the LiveReload support is rendedered into HTML if

to create a minimal new site for testing, run:

docker run --user $(id -u):$(id -g) -itv $(pwd):/work haberlerm/docker-jekyll-asciidoctor jekyll new /work/newsite

#!/bin/bash -e
#JOPTS="JEKYLL_ENV=development" # default, add in livereload support
JOPTS=
if [ -d _site ] ; then
echo "_site exists, adding --incremental --skip-initial-build to options"
JOPTS="${JOPTS} --incremental --skip-initial-build"
fi
ip=$(hostname -i)
HTTP_PORT=4000
# set to IP address or hostname for the livereload
# server. Defaults to $ip
SERVING_HOST=
IMAGE=haberlerm/docker-jekyll-asciidoctor
LRLOG=$(mktemp --tmpdir -t livereload.XXXXXXXXXX)
if [ ! -f _config_preview.yml ] ; then
echo creating a _config_preview.yml file for $ip
echo please review, then re-run this script
cat >_config_preview.yml <<EOF
# livereload server ip & method
# expanded in _include/livereload.html
lrhost: $ip
lrmethod: http
# site URL
url: http://$ip:$HTTP_PORT
EOF
cat _config_preview.yml
exit 0
fi
# fetch the latestg docker image (4GB):
# once done, takes a few seconds, but will get you any updates
# automatically
# docker pull ${IMAGE}
bg_pid="none"
if ! [ -x "$(command -v livereload)" ]; then
echo "livereload not installed, skipped." >&2
echo "install with 'pip install livereload'" >&2
else
lrcmd="livereload --host ${SERVING_HOST:-$ip} _site"
echo running $lrcmd
nohup $lrcmd >$LRLOG 2>&1 </dev/null &
bg_pid=$!
echo livereload pid $bg_pid logging to $LRLOG
fi
function finish {
if [ "$bg_pid" != "none" ] ; then
echo exit livereload pid=$bg_pid
kill -TERM $bg_pid # exit livereload
fi
}
trap finish EXIT
docker run \
--user $(id -u):$(id -g) \
-p ${HTTP_PORT}:${HTTP_PORT} \
-it -v $(pwd):/work ${IMAGE} \
jekyll serve \
--host=0.0.0.0 \
--port=${HTTP_PORT} \
--verbose \
--trace \
--watch \
--config _config.yml,_config_devel.yml,_config_preview.yml \
${JOPTS} \
$@
@mhaberler
Copy link
Author

updated serve.sh so it behaves more intelligently if _site exists: in that case, run jekyll with --incremental --skip-initial-build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment