aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2023-11-09 14:56:21 -0500
committerNick Mathewson <nickm@torproject.org>2023-11-09 16:42:47 -0500
commit729b79c61b9ac979563f34118add1d6b2ebd022f (patch)
treed43036e8ac5a5d77a0366f0135b8e356557f3100 /bin
parentb9ba76e22180aaf1a3c848c74e4019727f7375ec (diff)
downloadtorspec-729b79c61b9ac979563f34118add1d6b2ebd022f.tar.gz
torspec-729b79c61b9ac979563f34118add1d6b2ebd022f.zip
Make mmdc optional.
The build script now only uses mmdc and a temporary conditionally, and otherwise (for now) leaves mermaid blocks unformatted.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/build_html22
-rwxr-xr-xbin/mermaid_cvt_svg15
2 files changed, 24 insertions, 13 deletions
diff --git a/bin/build_html b/bin/build_html
index 533e17c..04b1f5e 100755
--- a/bin/build_html
+++ b/bin/build_html
@@ -10,12 +10,22 @@ cd "${TOPLEVEL}"
./bin/make_redirects
-./bin/mermaid_cvt_svg
-
-trap 'rm -rf ${TOPLEVEL}/tmp_mermaid' 0
-
-cd "${TOPLEVEL}/mdbook/spec"
+if test -n "${MMDC:-}" || command -v "mmdc" >&/dev/null; then
+ TMPDIR=$(mktemp -d "${TOPLEVEL}/tmp_mmdc.XXXXXXXX")
+ trap 'rm -rf "$TMPDIR"' 0
+ ./bin/mermaid_cvt_svg "$TMPDIR"
+ BUILD_ROOT="$TMPDIR"
+else
+ BUILD_ROOT="$TOPLEVEL"
+fi
+
+cd "${BUILD_ROOT}/mdbook/spec"
$MDBOOK build
-cd "${TOPLEVEL}/mdbook/proposals"
+cd "${BUILD_ROOT}/mdbook/proposals"
$MDBOOK build
+
+if test "${BUILD_ROOT}" != "${TOPLEVEL}"; then
+ rm -rf "${TOPLEVEL}/html"
+ mv "${BUILD_ROOT}/html" "${TOPLEVEL}/html"
+fi
diff --git a/bin/mermaid_cvt_svg b/bin/mermaid_cvt_svg
index 11aa596..3198a00 100755
--- a/bin/mermaid_cvt_svg
+++ b/bin/mermaid_cvt_svg
@@ -3,22 +3,23 @@
set -e -u -o pipefail -x
TOPLEVEL=$(realpath $(dirname "$0"))/..
+TMPDIR="$1"
: ${MMDC:=mmdc}
-# We can't use mktemp here, since we need the actual
-# path in build.html
-TMPDIR="${TOPLEVEL}/tmp_mermaid/"
-rm -rf "$TMPDIR"
-mkdir -p "${TOPLEVEL}/tmp_mermaid/"
+cd "$TOPLEVEL"
# We make a mirror of the specs, since we will need to make changes to them.
-cp -rl spec ./tmp_mermaid/spec
+cp -rl spec proposals mdbook "$TMPDIR"
+
# We use mermaid-cli to extract the mermaid from any file containing it,
# and generate a new version that uses svg instead.
-for fname in $(find ./tmp_mermaid -name "*.md") ; do
+for fname in $(find "$TMPDIR" -name "*.md") ; do
if grep '^```mermaid' $fname; then
ORIG="${fname%.md}.__orig.md"
mv $fname $ORIG
$MMDC -i $ORIG -o $fname
fi
done
+
+
+