docs: use flat navigation.pages for multi-repo sourceRef (#386)

This commit is contained in:
Matt Apperson
2026-07-01 20:25:35 -04:00
committed by GitHub
parent 28299a788d
commit ebd01743bc
2 changed files with 49 additions and 66 deletions
+29 -39
View File
@@ -8,45 +8,35 @@
"dark": "#6467f2" "dark": "#6467f2"
}, },
"navigation": { "navigation": {
"groups": [ "pages": [
{ "overview",
"group": "Getting Started", "sdks/analytics/README",
"pages": [ "sdks/apikeys/README",
"overview" "sdks/benchmarks/README",
] "sdks/betaanalytics/README",
}, "sdks/byok/README",
{ "sdks/chat/README",
"group": "API Reference", "sdks/classifications/README",
"pages": [ "sdks/credits/README",
"sdks/analytics/README", "sdks/datasets/README",
"sdks/apikeys/README", "sdks/embeddings/README",
"sdks/benchmarks/README", "sdks/endpoints/README",
"sdks/betaanalytics/README", "sdks/files/README",
"sdks/byok/README", "sdks/generations/README",
"sdks/chat/README", "sdks/guardrails/README",
"sdks/classifications/README", "sdks/images/README",
"sdks/credits/README", "sdks/models/README",
"sdks/datasets/README", "sdks/oauth/README",
"sdks/embeddings/README", "sdks/observability/README",
"sdks/endpoints/README", "sdks/organization/README",
"sdks/files/README", "sdks/presets/README",
"sdks/generations/README", "sdks/providers/README",
"sdks/guardrails/README", "sdks/rerank/README",
"sdks/images/README", "sdks/responses/README",
"sdks/models/README", "sdks/stt/README",
"sdks/oauth/README", "sdks/tts/README",
"sdks/observability/README", "sdks/videogeneration/README",
"sdks/organization/README", "sdks/workspaces/README"
"sdks/presets/README",
"sdks/providers/README",
"sdks/rerank/README",
"sdks/responses/README",
"sdks/stt/README",
"sdks/tts/README",
"sdks/videogeneration/README",
"sdks/workspaces/README"
]
}
] ]
} }
} }
+20 -27
View File
@@ -1,12 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Regenerate the "API Reference" navigation group in docs/docs.json from the # Regenerate docs/docs.json navigation from the service pages Speakeasy emits
# service pages Speakeasy emits under docs/sdks/<tag>/README.mdx. # under docs/sdks/<tag>/README.mdx.
# #
# Run this after `speakeasy run` so new API sections appear in the sidebar # The docs.json exposes a flat `navigation.pages` array so it can be mounted
# without hand-editing docs.json. Only the "API Reference" group's `pages` # into the base docs site via a `sourceRef` inside a `pages` context (Mintlify
# array is rewritten; every other part of docs.json is preserved untouched. # requires the referenced source to define the same navigation type as the slot
# Pages are listed alphabetically by tag. Idempotent: running with no doc # it is mounted into). The array is: the "overview" page first, then every
# changes leaves docs.json byte-identical. # service page sorted alphabetically by tag.
#
# Run after `speakeasy run` so new API sections appear without hand-editing
# docs.json. Only `navigation.pages` is rewritten; $schema/theme/name/colors
# are preserved. Idempotent: no doc changes -> byte-identical output.
# #
# Requires: bash, jq. No network, no toolchain. # Requires: bash, jq. No network, no toolchain.
set -euo pipefail set -euo pipefail
@@ -15,16 +19,18 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT" cd "$ROOT"
DOCS_JSON="docs/docs.json" DOCS_JSON="docs/docs.json"
GROUP="API Reference" OVERVIEW="overview"
if [[ ! -f "$DOCS_JSON" ]]; then if [[ ! -f "$DOCS_JSON" ]]; then
echo "missing $DOCS_JSON" >&2 echo "missing $DOCS_JSON" >&2
exit 1 exit 1
fi fi
# Collect service page paths (docs.json paths are repo-doc-root-relative and # Collect service page paths (docs.json paths are doc-root-relative, no
# carry no extension), sorted alphabetically by tag. # extension), sorted alphabetically by tag.
pages=() pages=()
# Lead with the overview landing page when present.
[[ -f "docs/${OVERVIEW}.mdx" ]] && pages+=("$OVERVIEW")
while IFS= read -r readme; do while IFS= read -r readme; do
# docs/sdks/<tag>/README.mdx -> sdks/<tag>/README # docs/sdks/<tag>/README.mdx -> sdks/<tag>/README
rel="${readme#docs/}" rel="${readme#docs/}"
@@ -32,29 +38,16 @@ while IFS= read -r readme; do
done < <(find docs/sdks -mindepth 2 -maxdepth 2 -name 'README.mdx' | sort) done < <(find docs/sdks -mindepth 2 -maxdepth 2 -name 'README.mdx' | sort)
if ((${#pages[@]} == 0)); then if ((${#pages[@]} == 0)); then
echo "no service pages found under docs/sdks/*/README.mdx" >&2 echo "no pages found (missing docs/${OVERVIEW}.mdx and docs/sdks/*/README.mdx)" >&2
exit 1 exit 1
fi fi
# Build a JSON array of the page paths.
pages_json="$(printf '%s\n' "${pages[@]}" | jq -R . | jq -s .)" pages_json="$(printf '%s\n' "${pages[@]}" | jq -R . | jq -s .)"
# Rewrite only the matching group's pages. Fail loudly if the group is absent
# so a renamed/missing group never silently produces an empty sidebar.
tmp="$(mktemp)" tmp="$(mktemp)"
jq --indent 2 \ jq --indent 2 --argjson pages "$pages_json" '
--arg group "$GROUP" \ .navigation = {pages: $pages}
--argjson pages "$pages_json" '
(.navigation.groups
| map(select(.group == $group))
| length) as $matches
| if $matches == 0 then
error("group \"" + $group + "\" not found in navigation.groups")
else . end
| .navigation.groups |= map(
if .group == $group then .pages = $pages else . end
)
' "$DOCS_JSON" >"$tmp" ' "$DOCS_JSON" >"$tmp"
mv "$tmp" "$DOCS_JSON" mv "$tmp" "$DOCS_JSON"
echo "updated $DOCS_JSON: ${#pages[@]} pages in \"$GROUP\"" echo "updated $DOCS_JSON: ${#pages[@]} pages in navigation.pages"