#!/usr/bin/env bash set -e -u -o pipefail -x : ${MDBOOK:=mdbook} TOPLEVEL=$(realpath $(dirname "$0"))/.. cd "${TOPLEVEL}" ./bin/reindex ./bin/make_redirects # Now we deal with mermaid diagrams. # # This may require changes to the md files in {spec,proposals} # or to the mdbook.toml files in mdbook/*/. # We will make a copy of whatever we need to change, # and then make changes to that copy. # # When we are done with these changes, we will set some variables: # - HTML_OUTPUT_DIR is "", or the location where we have put our output. # - MDBOOK_DIR is the parent directory of the possibly modified copies # of mdbook/{spec,proposals}. if test -n "${MMDC:-}" || command -v "mmdc" >&/dev/null; then # CASE 1: mermaid-cli is installed. # # We will convert mermaid diagrams to svg. The mermaid_cvt_svg # script does this with a temporary copy of our markdown directories, # so as not to alter the original. # # (The conversion involves npm and a headless chrome browser, # to it is understandable that not everybody would want to do it # this way.) TMPDIR=$(mktemp -d "${TOPLEVEL}/tmp_mmdc.XXXXXXXX") trap 'rm -rf "$TMPDIR"' 0 ./bin/mermaid_cvt_svg "$TMPDIR" HTML_OUTPUT_DIR="$TMPDIR/html" MDBOOK_DIR="$TMPDIR/mdbook" elif test -n "${MDBOOK_MERMAID:-}" || command -v "mdbook-mermaid" >&/dev/null; then # CASE 2: mdbook_mermaid is installed. # # We will make a temporary copy of the mdbook configuration directory # only, and use mdbook-mermaid to alter that. # # This is much easier to run locally, but it requires that your # browser has enough client-side javascript in order to run # mermaid. It doesn't touch npm. MDBOOK_MERMAID=${MDBOOK_MERMAID:=mdbook-mermaid} TMPDIR=$(mktemp -d "${TOPLEVEL}/tmp_mdbook_mermaid.XXXXXXXX") trap 'rm -rf "$TMPDIR"' 0 cp -r ./mdbook/proposals ./mdbook/spec ./mdbook/theme "$TMPDIR" mdbook-mermaid install "$TMPDIR/spec" mdbook-mermaid install "$TMPDIR/proposals" HTML_OUTPUT_DIR="" MDBOOK_DIR="$TMPDIR" else # CASE 3: No mermaid support. # # In this case we run mdbook on our inputs unchanged. # The mermaid blocks will render as code. HTML_OUTPUT_DIR="" MDBOOK_DIR="$TOPLEVEL/mdbook" fi cd "${MDBOOK_DIR}/spec" $MDBOOK build cd "${MDBOOK_DIR}/proposals" $MDBOOK build if test -n "${HTML_OUTPUT_DIR}"; then rm -rf "${TOPLEVEL}/html" mv "${HTML_OUTPUT_DIR}" "${TOPLEVEL}/html" fi