blob: 26fd7d8c02d7fb0fe6611fc042ae07ffa72efa8e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/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
|