Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 49 lines (36 sloc) 1.3 KB
#!/usr/bin/env bash
#
# Generate HTML from markdown files, and copy resources,
# to produce a complete website.
set -o errexit -o nounset -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -r SCRIPT_DIR
declare -r WEBSITE="${1:-}"
if [[ -z "${WEBSITE}" ]]; then
echo >&2 "Usage: $0 <website>"
exit 1
fi
declare -r WEBSITE_MARKDOWN="${SCRIPT_DIR}/${WEBSITE%%\.*}.markdown"
declare -r WEBSITE_HTML="${SCRIPT_DIR}/${WEBSITE}"
declare -r DATA_DIR="${WEBSITE_MARKDOWN}/pandocomatic"
declare -r INPUT_DIR="${WEBSITE_MARKDOWN}/content"
declare -r OUTPUT_DIR="${WEBSITE_HTML}"
declare -r RESOURCES_DIR="${WEBSITE_MARKDOWN}/resources"
echo >&2 "Generating [${WEBSITE}]"
start_time="$(date +%s)"
declare -r start_time
# Copy all resources to output, and delete anything in output that
# is not in resources - this will remove any generated HTML, which
# is OK (and preferred) b/c we're going to generate fresh HTML next.
rsync -a --delete "${RESOURCES_DIR}/" "${OUTPUT_DIR}/"
# Generate fresh HTML from the markdown files.
pandocomatic \
--quiet \
--data-dir "${DATA_DIR}" \
--input "${INPUT_DIR}" \
--output "${OUTPUT_DIR}"
end_time="$(date +%s)"
declare -r end_time
((elapsed_time = end_time - start_time))
declare -r elapsed_time
echo "Website updated in [${elapsed_time}] seconds"