11#! /usr/bin/env bash
2- # Regenerate the "API Reference" navigation group in docs/docs.json from the
3- # service pages Speakeasy emits under docs/sdks/<tag>/README.mdx.
2+ # Regenerate docs/docs.json navigation from the service pages Speakeasy emits
3+ # under docs/sdks/<tag>/README.mdx.
44#
5- # Run this after `speakeasy run` so new API sections appear in the sidebar
6- # without hand-editing docs.json. Only the "API Reference" group's `pages`
7- # array is rewritten; every other part of docs.json is preserved untouched.
8- # Pages are listed alphabetically by tag. Idempotent: running with no doc
9- # changes leaves docs.json byte-identical.
5+ # The docs.json exposes a flat `navigation.pages` array so it can be mounted
6+ # into the base docs site via a `sourceRef` inside a `pages` context (Mintlify
7+ # requires the referenced source to define the same navigation type as the slot
8+ # it is mounted into). The array is: the "overview" page first, then every
9+ # service page sorted alphabetically by tag.
10+ #
11+ # Run after `speakeasy run` so new API sections appear without hand-editing
12+ # docs.json. Only `navigation.pages` is rewritten; $schema/theme/name/colors
13+ # are preserved. Idempotent: no doc changes -> byte-identical output.
1014#
1115# Requires: bash, jq. No network, no toolchain.
1216set -euo pipefail
@@ -15,46 +19,35 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
1519cd " $ROOT "
1620
1721DOCS_JSON=" docs/docs.json"
18- GROUP= " API Reference "
22+ OVERVIEW= " overview "
1923
2024if [[ ! -f " $DOCS_JSON " ]]; then
2125 echo " missing $DOCS_JSON " >&2
2226 exit 1
2327fi
2428
25- # Collect service page paths (docs.json paths are repo- doc-root-relative and
26- # carry no extension), sorted alphabetically by tag.
29+ # Collect service page paths (docs.json paths are doc-root-relative, no
30+ # extension), sorted alphabetically by tag.
2731pages=()
32+ # Lead with the overview landing page when present.
33+ [[ -f " docs/${OVERVIEW} .mdx" ]] && pages+=(" $OVERVIEW " )
2834while IFS= read -r readme; do
2935 # docs/sdks/<tag>/README.mdx -> sdks/<tag>/README
3036 rel=" ${readme# docs/ } "
3137 pages+=(" ${rel% .mdx} " )
3238done < <( find docs/sdks -mindepth 2 -maxdepth 2 -name ' README.mdx' | sort)
3339
3440if (( ${# pages[@]} == 0 )) ; then
35- echo " no service pages found under docs/sdks/*/README.mdx" >&2
41+ echo " no pages found (missing docs/${OVERVIEW} .mdx and docs/ sdks/*/README.mdx) " >&2
3642 exit 1
3743fi
3844
39- # Build a JSON array of the page paths.
4045pages_json=" $( printf ' %s\n' " ${pages[@]} " | jq -R . | jq -s .) "
4146
42- # Rewrite only the matching group's pages. Fail loudly if the group is absent
43- # so a renamed/missing group never silently produces an empty sidebar.
4447tmp=" $( mktemp) "
45- jq --indent 2 \
46- --arg group " $GROUP " \
47- --argjson pages " $pages_json " '
48- (.navigation.groups
49- | map(select(.group == $group))
50- | length) as $matches
51- | if $matches == 0 then
52- error("group \"" + $group + "\" not found in navigation.groups")
53- else . end
54- | .navigation.groups |= map(
55- if .group == $group then .pages = $pages else . end
56- )
48+ jq --indent 2 --argjson pages " $pages_json " '
49+ .navigation = {pages: $pages}
5750' " $DOCS_JSON " > " $tmp "
5851
5952mv " $tmp " " $DOCS_JSON "
60- echo " updated $DOCS_JSON : ${# pages[@]} pages in \" $GROUP \" "
53+ echo " updated $DOCS_JSON : ${# pages[@]} pages in navigation.pages "
0 commit comments