11#! /usr/bin/env bash
22#
3- # Build combined v1 + v2 MkDocs documentation for GitHub Pages.
3+ # Build combined v1 + v2 documentation for GitHub Pages.
44#
55# v1 docs (from the v1.x branch) are placed at the site root.
66# v2 docs (from main) are placed under /v2/.
77#
8- # Both branches are fetched fresh from origin, so the output is identical
9- # regardless of which branch triggered the workflow. This script is intended
10- # to run in CI; for local single-branch preview use `uv run mkdocs serve`.
8+ # The two lines use different toolchains: v1.x still builds with MkDocs, while
9+ # main builds with Zensical (which needs a pre-build step to materialise the API
10+ # reference and a post-build step for llms.txt — see scripts/docs/). Each branch
11+ # is fetched fresh from origin and built with its own synced `docs` group, so
12+ # the output is identical regardless of which branch triggered the workflow.
13+ # This script is intended to run in CI; for a local v2 preview use
14+ # `scripts/serve-docs.sh`.
1115#
1216# Usage:
1317# scripts/build-docs.sh [output-dir]
@@ -30,7 +34,21 @@ cleanup() {
3034}
3135trap cleanup EXIT
3236
33- rm -rf " ${OUTPUT_DIR:? } " /*
37+ # Build the checked-out worktree into its local `site/`, picking the toolchain
38+ # from the branch's own files rather than hard-coding it here: a branch that
39+ # ships the Zensical build recipe (scripts/docs/build.sh) builds with it,
40+ # otherwise it falls back to MkDocs. This keeps the combined build correct
41+ # regardless of which branch triggered it. Zensical requires site_dir to live
42+ # within the project root, so both paths build to the local `site/` and let
43+ # the caller copy it to its destination.
44+ build_site () {
45+ if [[ -f scripts/docs/build.sh ]]; then
46+ bash scripts/docs/build.sh
47+ else
48+ uv sync --frozen --group docs
49+ NO_MKDOCS_2_WARNING=1 uv run --frozen --no-sync mkdocs build --site-dir site
50+ fi
51+ }
3452
3553build_branch () {
3654 local branch=" $1 " worktree=" $2 " dest=" $3 "
@@ -43,11 +61,15 @@ build_branch() {
4361
4462 (
4563 cd " $worktree "
46- uv sync --frozen --group docs
47- uv run --frozen --no-sync mkdocs build --site-dir " $dest "
64+ rm -rf site
65+ build_site
66+ mkdir -p " $dest "
67+ cp -a site/. " $dest /"
4868 )
4969}
5070
71+ rm -rf " ${OUTPUT_DIR:? } " /*
72+
5173build_branch v1.x " $V1_WORKTREE " " $OUTPUT_DIR "
5274build_branch main " $V2_WORKTREE " " $OUTPUT_DIR /v2"
5375
0 commit comments