The first version cut (v0.1.0) revealed a real gap: nothing in the
rendered book identified which release the reader was on. The
version-picker chip says "version: v0.1.0" when you're on /v0.1.0/,
but it's a small UI affordance — and on /latest/ it can't say
"v0.1.0" because /latest/ is the rolling main build, not the v0.1.0
release.
Two complementary fixes, both visible without JS:
1. **Body marker.** Top of every chapter-0 (overview) page now reads
`Spec version: <token>`. The token is `latest (main)` in src/, and
gets frozen to the actual version (`v0.1.0`) when cut-version
snapshots the directory. So /latest/ overview says "latest (main)"
and /v0.1.0/ overview says "v0.1.0".
2. **Per-build page title.** scripts/build-site.sh now sets
`MDBOOK_BOOK__TITLE` for each build:
- latest → "MeshCore Protocol Specification — latest (main)"
- vX.Y.Z → "MeshCore Protocol Specification — vX.Y.Z"
The browser tab and mdBook sidebar header reflect the version.
`just cut-version` updated to run a one-line sed on the snapshot's
00-overview.md replacing the `latest (main)` marker. Defensive grep
warns if the marker isn't found (e.g., src/ was edited away from
the expected line).
versions/v0.1.0/00-overview.md regenerated by re-running
`just cut-version v0.1.0` after the marker landed in src/ — so the
v0.1.0 snapshot now self-identifies correctly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
2.8 KiB
Bash
Executable File
93 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
# Build the full multi-version site into ./_site/:
|
|
# - "latest" from ./src/
|
|
# - one subtree per ./versions/vX.Y.Z/ directory
|
|
#
|
|
# Each per-version build uses today's repo-root build infrastructure
|
|
# (book.toml, theme/, picker JS, scripts/), only swapping in the
|
|
# frozen content directory via MDBOOK_BOOK__SRC. This means every
|
|
# deploy gives every published version the current theme — site
|
|
# improvements never need backporting to old snapshots.
|
|
#
|
|
# Emits _site/versions.json (newest first; consumed by
|
|
# theme/version-picker.js) and _site/index.html (redirect to /latest/).
|
|
#
|
|
# Cut a new frozen version with `just cut-version vX.Y.Z`, which
|
|
# snapshots ./src/ into ./versions/vX.Y.Z/.
|
|
|
|
set -eu
|
|
|
|
SITE_BASE="${SITE_BASE:-/meshcore-spec}"
|
|
WORKSPACE="$(pwd)"
|
|
SITE_DIR="$WORKSPACE/_site"
|
|
|
|
group() { printf '::group::%s\n' "$1"; }
|
|
endgroup() { printf '::endgroup::\n'; }
|
|
warn() { printf '::warning::%s\n' "$1"; }
|
|
|
|
rm -rf "$SITE_DIR"
|
|
mkdir -p "$SITE_DIR"
|
|
|
|
# ---- latest (from src/) ----
|
|
group "build latest"
|
|
MDBOOK_BOOK__TITLE="MeshCore Protocol Specification — latest (main)" \
|
|
MDBOOK_OUTPUT__HTML__SITE_URL="${SITE_BASE}/latest/" \
|
|
mdbook build "$WORKSPACE" -d "$SITE_DIR/latest"
|
|
endgroup
|
|
|
|
# ---- frozen versions (./versions/v*) ----
|
|
# Discover and sort by semver (newest first). The list is captured
|
|
# into a variable so we can iterate it twice — once to build, once to
|
|
# emit versions.json — without re-scanning.
|
|
list_versions() {
|
|
for d in versions/v*; do
|
|
[ -d "$d" ] || continue
|
|
basename "$d"
|
|
done | sort -V -r
|
|
}
|
|
VERSION_DIRS="$(list_versions)"
|
|
|
|
for version in $VERSION_DIRS; do
|
|
vdir="versions/$version"
|
|
[ -d "$vdir" ] || continue
|
|
group "build $version"
|
|
if ! MDBOOK_BOOK__SRC="$vdir" \
|
|
MDBOOK_BOOK__TITLE="MeshCore Protocol Specification — ${version}" \
|
|
MDBOOK_OUTPUT__HTML__SITE_URL="${SITE_BASE}/${version}/" \
|
|
mdbook build "$WORKSPACE" -d "$SITE_DIR/${version}"; then
|
|
warn "mdbook build failed for ${version}; skipping"
|
|
rm -rf "${SITE_DIR:?}/${version:?}"
|
|
fi
|
|
endgroup
|
|
done
|
|
|
|
# ---- versions.json (consumed by theme/version-picker.js) ----
|
|
# "latest" always first; then each successfully-built frozen version.
|
|
{
|
|
printf '['
|
|
printf '"latest"'
|
|
for version in $VERSION_DIRS; do
|
|
[ -d "$SITE_DIR/$version" ] || continue
|
|
printf ',"%s"' "$version"
|
|
done
|
|
printf ']\n'
|
|
} > "$SITE_DIR/versions.json"
|
|
echo "versions.json:"
|
|
cat "$SITE_DIR/versions.json"
|
|
|
|
# ---- root redirect to /latest/ ----
|
|
cat > "$SITE_DIR/index.html" <<'HTML'
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="refresh" content="0; url=./latest/">
|
|
<link rel="canonical" href="./latest/">
|
|
<title>MeshCore Protocol Specification</title>
|
|
</head>
|
|
<body>
|
|
<p>Redirecting to the <a href="./latest/">latest version</a>…</p>
|
|
</body>
|
|
</html>
|
|
HTML
|