Sync docs across repositories
Use this when one repository owns package code and MDX, but another repository owns the rendered docs UI. Start with a remote collection pinned in the docs UI repo, inherit the source-owned docs config, then choose how that pin gets updated.
The important part is not repository_dispatch. The important part is that the docs UI repo has a durable Leadtype remote collection that says exactly which source revision to render:
That remote collection makes docs deploys reproducible. If 1.0.0 is live and
main is halfway to 2.0.0, a Vercel, Cloudflare Pages, Netlify,
self-hosted CI, or local redeploy still renders the 1.0.0 docs.
The ownership model is intentionally narrow:
- Source repo owns MDX, navigation/sidebar order, fallback groups, frontmatter schema, and source-specific flatteners.
- Docs UI repo owns product identity as rendered by the site, organization,
agent policy, source
repository/ref, output paths, hosting, analytics, and the app shell.
Recommended flow
The safest default is a manual promotion:
- Release the package from the source repo.
- Update the remote collection
refin the docs UI repo to the release commit SHA. - Open a PR in the docs UI repo.
- Review the docs preview.
- Merge the PR to deploy production docs.
This keeps production docs as an explicit promotion step. It is provider-neutral and easy to debug because the docs UI repo records the exact source revision it is rendering.
Configure the remote collection
Keep the source repo and commit SHA in leadtype.config.ts:
With sourceConfig: true, the source repo keeps the docs-specific config that
belongs with the content: navigation, legacy groups, frontmatterSchema,
source-specific flatteners, and same-tree mounts such as
docs/changelog -> /changelog. The docs UI repo keeps the deployment pin and
site-owned fields: repository, ref, cacheDir, product identity as rendered
by the site, organization, agent policy, output directory, base URL, and the app
shell.
Then sync and generate before the framework build:
Use the same script shape for Astro, Nuxt, SvelteKit, TanStack Start, Vite, or a static file deploy. The framework only needs to render the human docs UI and serve the generated files.
Use leadtype generate --offline in CI jobs or local checks that must never
touch the network. Offline generation still loads the inherited source config
from the existing cache, and fails if the configured ref is not already
synced.
If the docs UI repo uses the released package at build time, pin that dependency to the same version in the same PR and refresh the lockfile. That pins both the docs content and the package code used to render or generate it.
How Leadtype dogfoods this
The framework apps in apps/* are integration examples. The production
Leadtype docs site is a separate docs UI app that renders leadtype.dev and
syncs the Leadtype source repository into .leadtype.
Before sourceConfig, that app needed a custom source file (leadtype-source.json),
a custom clone script, and a custom import of .leadtype/docs/docs.config.ts to
reuse the source-owned navigation. With sourceConfig: true, the app can move
that source ownership into first-class Leadtype config:
The source repo keeps docs/docs.config.ts, MDX, navigation, groups,
frontmatter schema, source-specific flatteners, and mounts. The Leadtype docs UI
app keeps the app shell, consent, analytics, search UI, package dependency pin,
and production source ref.
Optional automation: open the pin PR
Automation is useful when you want every package release to propose a docs update. In that setup, repository_dispatch is only the cross-repo notification. The docs UI repo still opens a PR and waits for review.
Dispatch a small immutable payload after publish:
repo and sha are enough to fetch the exact docs. version is useful for PR titles, dependency pins, build logs, and release dashboards.
Source repo release workflow
Dispatch after the package publish step succeeds. A fine-grained token or GitHub App token needs write access to contents on the target docs repo because the GitHub API treats repository_dispatch as a write operation. Keep the target workflow on the docs repo's default branch; GitHub only starts repository_dispatch workflows from there.
Store:
DOCS_DISPATCH_TOKENas a secret in the source repo.DOCS_REPOSITORYas a repo variable, for exampleacme/docs.DOCS_PACKAGE_NAMEas a repo variable set to the published package that drives docs pins, for example@acme/sdk.
Docs repo PR workflow
The docs UI repo receives the event, updates the remote collection ref on a branch, and opens a PR. Your hosting provider can build PR previews from the docs UI repo as usual.
By default peter-evans/create-pull-request opens the PR with the workflow's GITHUB_TOKEN, and PRs created that way do not trigger downstream push or pull_request workflows on the docs repo. Hosting-provider previews (Vercel, Cloudflare Pages, Netlify) still build because they run through their own GitHub Apps, but workflow-driven CI on the pin PR — link checks, MDX lint, leadtype lint — silently will not run. If you need those, pass a fine-grained PAT or GitHub App token via the action's token: input.
Keep scripts/update-leadtype-source.mjs in the docs UI repo so the repo owns how its Leadtype config is edited. Prefer a small AST-aware script or a deliberately marked config block over ad hoc shell replacement. If you also pin the released package dependency, update package.json and the lockfile before Open pin PR.
Deployment options
| Option | Use when | Tradeoff |
|---|---|---|
| Manual pin PR | You want the clearest and safest release promotion. | Recommended baseline. Requires a maintainer to update and merge. |
| Dispatch opens pin PR | You want release automation but still want review before production docs change. | Recommended automation path. Needs a cross-repo token. |
| Dispatch commits to main | You want publish to deploy docs automatically. | Fast, but couples npm publish directly to docs production. Avoid as the default. |
| Provider deploy hook | You only need "rebuild now" and the source ref already lives in the docs repo. | Too weak by itself; hooks do not carry a durable pin. |
| Release artifact | You want a hermetic tarball of generated markdown/search artifacts. | Strong reproducibility, but more storage and promotion plumbing. |
| Git submodule or subtree | You want the docs repo to vendor the source revision directly. | Reproducible, but heavier contributor DX than a remote collection ref. |
| Same repo | The docs UI and packages ship together. | Simplest when ownership allows it. |
Preview builds
For PR previews, do not update the production pin. Either:
- Let the docs UI repo build previews from source branches by passing a temporary SHA to preview-only CI.
- Dispatch preview events from same-repo PRs only, and require a maintainer-triggered workflow for fork previews.
Keep preview refs separate from the production remote collection ref.
Agent prompt
You are setting up a multi-repo Leadtype docs pipeline.
Requirements:
- The package/source repo owns MDX and releases packages.
- The docs UI repo owns the rendered site.
- Production docs must be pinned to an explicit released source revision, not the source repo default branch.
- Configure
leadtype.config.tsin the docs UI repo with a remote Leadtype collection whoserepositorypoints at the source repo, whoserefis pinned to the released commit SHA, and whosesourceConfigistrue.- Keep source-owned
navigation, legacygroups,frontmatterSchema,flatteners, andmountsin the source repo'sdocs/docs.config.ts.- Keep the package version near that config when useful for reviewers, PR titles, dependency pins, or release dashboards.
- Run
leadtype generate --syncbefore the docs UI framework build. Use--offlineonly when the cache is already present.- Prefer manual pin PRs as the baseline. If automating, make the source repo dispatch a small payload after publish and make the docs UI repo open a PR that updates the remote collection ref.
- Do not make package publish directly deploy production docs unless the project explicitly wants that coupling.
- For PR previews, do not update the production pin. Keep preview refs separate.
Return the changed workflows, the remote collection shape, required secrets and variables, and the build scripts needed for the docs UI repo.