/ scripts / dev / build-docs.sh
build-docs.sh
 1  #!/usr/bin/env bash
 2  
 3  set -euo pipefail
 4  
 5  source "./scripts/_common.sh"
 6  
 7  fm_index_md=${FM_RUSTDOC_INDEX_MD:-./docs/rustdoc-index.md}
 8  index_html="${CARGO_BUILD_TARGET_DIR:-target}/doc/index.html"
 9  
10  export RUSTDOCFLAGS='-D rustdoc::broken_intra_doc_links -D warnings -A unknown-lints'
11  if cargo version | grep -q nightly ; then
12    RUSTDOCFLAGS="$RUSTDOCFLAGS -Z unstable-options --enable-index-page"
13    # broken: https://github.com/rust-lang/rust/issues/97881
14    # RUSTDOCFLAGS="$RUSTDOCFLAGS --index-page ${FM_RUSTDOC_INDEX_MD:-./docs/rustdoc-index.md}"
15  fi
16  echo RUSTDOCFLAGS: "$RUSTDOCFLAGS"
17  
18  cargo doc --exclude fedimint-fuzz --profile "$CARGO_PROFILE" --locked --workspace --no-deps --document-private-items
19  
20  if [ -e "${index_html}" ]; then
21    if command -v pandoc >/dev/null 2>/dev/null ; then
22      # since `--index-page` is broken, improve our index page manually :/
23      pandoc "$fm_index_md" > "${fm_index_md}.html"
24      trap 'rm -f "${fm_index_md}.html"' EXIT
25  
26      sed -i 's#<title>Index of crates</title>#<title>Fedimint technical reference</title>#' "$index_html"
27  
28      awk -v insert_path="${fm_index_md}.html" '
29        BEGIN {
30          RS = ORS = "\0"; # Treat the file as a single record
31          while ((getline line < insert_path) > 0) {
32            content = content line "\n";
33          }
34          close(insert_path);
35        }
36        {
37          sub(/<section id="main-content"[^>]*>/, "&" content); # Replace MARKER with insert.txt content + MARKER
38          print;
39        }' "$index_html" > "$index_html.tmp" && mv "$index_html.tmp" "$index_html"
40    fi
41  fi