#!/usr/bin/env bash # Flatten rustdoc output so the crate serves at the doc root rather than under # /. Moves the crate's pages up to the doc root and drops one ../ from # each page's references to the shared assets (CSS/JS, search index, source), # scaled to the page's depth. # Env: DOCROOT (default target/doc), CRATE (default coursebank). set -euo pipefail docroot="${DOCROOT:-target/doc}" crate="${CRATE:-coursebank}" [ -d "$docroot/$crate" ] || { echo "no $docroot/$crate; did you build the docs?" >&2; exit 1; } cp -a "$docroot/$crate/." "$docroot/" rm -rf "${docroot:?}/${crate:?}" resources='static\.files/\|crates\.js\|search-index\|search\.desc/\|src/\|settings\.html\|help\.html\|trait\.impl/\|type\.impl/' while IFS= read -r -d '' f; do rel="${f#"$docroot"/}" depth=$(printf '%s' "$rel" | tr -cd '/' | wc -c) pat=''; for ((i=0; i<=depth; i++)); do pat="\\.\\./$pat"; done rep=''; for ((i=0; i