ci: separate docs into scripts
This commit is contained in:
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# Flatten rustdoc output so the crate serves at the doc root rather than under
|
||||
# <crate>/. 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<depth; i++)); do rep="../$rep"; done
|
||||
sed -i "s#${pat}\(${resources}\)#${rep}\1#g" "$f"
|
||||
done < <(find "$docroot" -name '*.html' -print0)
|
||||
echo "flattened $crate into $docroot"
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# Publish a built docs channel to the web root.
|
||||
# Usage: publish-docs.sh <release|nightly> [-d docroot] [-w www_root] [-s site_slug]
|
||||
# Env: DOCROOT (default target/doc), WWW_ROOT (default /srv/www),
|
||||
# SITE_SLUG (default coursebank).
|
||||
# Flags, if given, override the corresponding env var / default.
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 <release|nightly> [-d docroot] [-w www_root] [-s site_slug]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
channel="${1:?usage: publish-docs.sh <release|nightly> [-d docroot] [-w www_root] [-s site_slug]}"
|
||||
shift
|
||||
|
||||
docroot="${DOCROOT:-target/doc}"
|
||||
www_root="${WWW_ROOT:-/srv/www}"
|
||||
site_slug="${SITE_SLUG:-coursebank}"
|
||||
|
||||
while getopts "d:w:s:" opt; do
|
||||
case "$opt" in
|
||||
d) docroot="$OPTARG" ;;
|
||||
w) www_root="$OPTARG" ;;
|
||||
s) site_slug="$OPTARG" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
dest="${www_root}/${site_slug}/${channel}"
|
||||
mkdir -p "$dest"
|
||||
rsync -a --delete "$docroot/" "$dest/"
|
||||
echo "published $docroot -> $dest"
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# Point the site root at the latest release, falling back to nightly.
|
||||
# Env: WWW_ROOT (default /srv/www), SITE_SLUG (default coursebank).
|
||||
set -euo pipefail
|
||||
root="${WWW_ROOT:-/srv/www}/${SITE_SLUG:-coursebank}"
|
||||
if [ -e "$root/release/index.html" ]; then target="release/"; else target="nightly/"; fi
|
||||
printf '%s\n' "<!doctype html><meta http-equiv=\"refresh\" content=\"0; url=${target}\">" > "$root/index.html"
|
||||
echo "site root -> $target"
|
||||
Reference in New Issue
Block a user