Skip to content

Blog

How to keep Docusaurus docs in sync with your source code

Docusaurus keeps docs in sync with source code through the repository. It gives you three real sync tools: a monorepo, code blocks imported from files, and a build that fails on broken links.

Cover Image for How to keep Docusaurus docs in sync with your source code
Published on
Read time
9 min

Docusaurus keeps docs in sync with source code through the repository. It gives you three real sync tools: a monorepo, code blocks imported from files, and a build that fails on broken links. All three assume the code lives next to the docs. Answering that exact question in Docusaurus discussion #3722 in November 2020, a maintainer said that with docs and code in separate repositories, keeping them in sync is your job.

Your Docusaurus site lives in its own docs repository, and your SDK lives in another. An engineer renames a configuration option in the SDK. Every guide that names the old option is now wrong, and no Docusaurus tool flags it.

What Docusaurus already does to keep docs and code together

The installation guide suggests a monorepo when you document an existing project: "Then, your contributors can update the docs as they implement features."

Inside one repository, you can import a source file as raw text with raw-loader and render it in a <CodeBlock>. The docs add a warning: "This feature is experimental and might be subject to breaking API changes in the future."

In the configuration reference, onBrokenLinks defaults to throw, so a link to a moved or deleted page fails the build. It has two limits: "The broken links detection is only available for a production build (docusaurus build)." And onBrokenAnchors defaults to warn, so a dead heading link ships with a warning.

Versioning copies the full docs/ folder into versioned_docs/version-[versionName]/ when you create a version, and each copy is edited independently. The docs advise against versioning unless you need it, because it adds build time and complexity.

The docusaurus-openapi-docs plugin generates MDX "using the OpenAPI specification as the source." Palo Alto Networks maintains it under the MIT license, outside the official Docusaurus project.

Diagram: an SDK repo with a renamed option and a separate Docusaurus docs repo whose code imports and broken-link check stop at the repo edge; EkLine bridges the two by reading the change and opening a docs pull request

Where the renamed option slips through

Try it on your own site. Open the last merged SDK pull request that renamed an option. Did anything flag the guide that still names the old one? Each Docusaurus check answers a narrower question:

Native checkWhat it verifiesWhat it does not seeWhere EkLine fits
onBrokenLinksLinks to moved or deleted pages, in production buildsA guide that names a renamed option with every link intactAutomatic PR review treats "renamed configuration" as a high-confidence case
raw-loader importsCode blocks that match a file in the docs checkoutCode in a separate SDK repositoryThe GitHub App watches the SDK repository and writes to the docs repository
docusaurus-openapi-docsReference MDX generated from your specGuides and samples written around itThe Code Sample Review agent in Scheduled Agents checks those samples

The raw-loader example imports a relative path such as ./myComponent, so the file has to be reachable from the docs project, which in practice means it sits in the same checkout. A renamed option breaks no link, so onBrokenLinks has nothing to throw on. The build passes, and the guide still tells readers to set the old name.

With versioning on, the page in docs/ belongs to the current version, the frozen copy under versioned_docs/ also names the old option, and each copy changes only when someone edits it.

A build can also fail without failing your deploy. In a Docusaurus 3.9.2 issue about an .md and an .mdx file sharing one name, josh-wong reported that "a site with build errors still goes live instead of failing the deployment." The maintainer traced it to a custom build script whose pipe to tee made it exit with code 0.

A Docusaurus sync checklist for this week

  1. Move the docs into the code repository if your team can, so the guide edit rides in the same pull request as the rename.
  2. Replace pasted snippets with raw-loader imports wherever the code shares the docs repository, and treat the experimental label as an upgrade risk.
  3. Run a full docusaurus build on every docs pull request, since link checks run only in production builds, and consider setting onBrokenAnchors to throw.
  4. Confirm that your build script exits non-zero on a Docusaurus error (a pipe to tee can hide the exit code), so your deploy job stops.
  5. After each SDK release, search docs/ and every versioned_docs/ folder for renamed options, and decide per version whether the frozen copy changes.
  6. Generate API reference pages from your OpenAPI spec with the community plugin, so review time goes to the guides.

Should you move the docs into the SDK monorepo?

For most teams it is the best native answer, and the Docusaurus installation guide suggests it for documenting an existing project: the guide sits in the same pull request as the rename. It still leaves the prose to whoever opens the pull request. The Docusaurus docs we reviewed describe no check that compares a guide's sentences with the code, and a rename's reason often sits in a ticket or Slack thread outside the pull request.

Here is the line. A monorepo plus a same-PR rule is enough when the pull request carries every fact the guide needs; that is the shared-repository case the maintainer described in discussion #3722. It stops being enough once a fact lives in a ticket, a Slack thread, a spec, or the separate SDK repository. Docs-first habits and nightly scripts are what practitioners describe in an Ask HN thread on keeping docs current.

How EkLine plugs into a Docusaurus repository

QuestionOn a Docusaurus site
Where your content livesYour docs repository, added in the EkLine GitHub App as a Documentation Repository, with paths such as docs/
What EkLine watchesYour SDK and service repositories, added separately as Code Repositories: "Source code repositories that EkLine reviews for documentation impact"
When it reads a changeAutomatic PR review assesses each pull request once, when it opens or leaves draft; a weekly Docs Drift Review audits the last 30 days of GitHub activity
Where its pull request landsYour docs repository, opened by Docs Agent
Which CI check runsDocs Reviewer, through the EkLine GitHub Action, posts inline comments on the pull request, covering style, consistency, links, and accuracy; Docs Reviewer accepts a docusaurus framework value, and "Support for other frameworks is expanding."
What stays in DocusaurusThe build, theme, plugins, versioning, previews, and hosting

When the engineer opens the SDK pull request, automatic PR review lists "renamed configuration" among its high-confidence cases, which "Posts a comment that automatically triggers the docs update flow." Docs Agent drafts the update as a pull request in the docs repository, where your build runs as usual and a reviewer merges or closes it. The assessment reads only the diff, title, and description; when the reason for the rename sits in a Jira ticket or a Slack thread, you can combine those sources in a Docs Agent session and get one pull request.

For snippets that raw-loader cannot reach, use the Code Sample Review agent in Scheduled Agents, which "Verifies that code samples in your docs are accurate and runnable." Docs Agent works with GitHub and GitLab and is available to all plans, with access granted on request.

Worried about engineering time? At P0 Security, which hosts its docs on GitBook, "In 6 months, engineers reclaimed 150+ hours of product development time by reviewing documentation instead of writing it."

If you are starting fresh or leaving Docusaurus

If you do leave, the target that puts the least of your accuracy work at risk keeps your docs as Markdown in Git, because the same pull request loop then works on the new repository. Potluck Docs is one such target: an MIT-licensed Astro + Starlight template maintained by EkLine, with OpenAPI references "rendered by Scalar with a built-in client for sending real requests," private docs behind your SSO, org-scoped docs, and a sitemap and llms.txt generated on every build. It is "a template, not a hosted product." Nothing about EkLine requires the move. Compare EkLine vs Docusaurus, or see Docusaurus alternatives.

FAQ

No. Docusaurus keeps building, versioning, and hosting your site. EkLine adds Docs Agent pull requests in your Docusaurus repository, drafted from changes in your SDK repositories, and Docs Reviewer comments in CI.

Through a shared repository. In discussion #3722, a maintainer replied that code and docs in the same Git repository "remain in sync automatically," and that with separate repositories "you have the responsibility to maintain sync." He linked an example of importing a code block from a source file. EkLine covers that separate-repository case.

Yes, from a file the build can reach. Import it as raw text with raw-loader and render it with <CodeBlock>. The feature is marked experimental, and the import is a relative path, so in practice the file sits in the docs checkout.

You can script part of it. In the Ask HN thread, cyanydeez described "a for loop that runs nightly on any files updated the prior day," and has local AI rewrite the Markdown file that sits next to each one. That pairing assumes the doc sits beside the code, the shared-repository case from discussion #3722; your guides live in a separate Docusaurus repository, and versioned copies multiply them. rstagi named the remaining cost: "it's hard to fact-check everything all the time." EkLine reads the SDK pull request and, when the impact is clear, opens a docs pull request your team reviews.


Bring the last SDK pull request that renamed an option. Book a demo and walk an SDK change through to a Docusaurus pull request.

Sources


Read more about

Cover Image for How to keep Astro Starlight docs accurate after a green build
Blog

How to keep Astro Starlight docs accurate after a green build

·9 min read

A green build tells you the site is well-formed: frontmatter matches its schema, internal links resolve once you add a validator, and API pages render from your spec. It cannot tell you whether a sentence in a how-to is still true, which takes a content check driven by what changed in the product.

Cover Image for How to keep Fumadocs docs in sync with your code
Blog

How to keep Fumadocs docs in sync with your code

·9 min read

To keep Fumadocs docs in sync with a Next.js app and its API, let Fumadocs generate every page it can from code (OpenAPI reference pages and TypeScript props tables), then give the hand-written guides around those pages an update loop of their own. A generated page changes when its source changes.

Cover Image for How to keep GitBook in sync with GitHub, and accurate
Blog

How to keep GitBook in sync with GitHub, and accurate

·9 min read

To keep GitBook in sync with GitHub without losing edits, and keep the content accurate, turn on Git Sync, choose the first sync direction on purpose, and edit each page in one place while a change is open. That keeps the editor and your repository identical.

Cover Image for How to keep Mintlify docs up to date when code changes
Blog

How to keep Mintlify docs up to date when code changes

·9 min read

Mintlify already automates the structural half of keeping docs current: it builds API reference pages from your OpenAPI spec, checks links, validates builds, syncs with GitHub, and can draft pull requests when code merges. The half that slips is the prose and the examples whose facts live in other repositories, tickets, and threads.

Cover Image for How to keep ReadMe docs in sync with your code and OpenAPI spec
Blog

How to keep ReadMe docs in sync with your code and OpenAPI spec

·9 min read

When you re-sync an OpenAPI file, ReadMe updates the spec-derived parts of each API page in place and leaves the Markdown you wrote alone. Your guides, recipes, and examples are that Markdown, so they need an update path of their own.

Cover Image for How to keep VitePress docs in sync with your code
Blog

How to keep VitePress docs in sync with your code

·9 min read

To keep VitePress docs in sync with your code, import every code sample from your source files and leave dead-link checking on, so the build fails when a linked page goes missing and, on the VitePress 2.0 alpha line, when an imported file goes missing. Then review the sentences next to those samples on each release, because no VitePress setting checks that prose against the code.

See what EkLine finds in your docs.

Book a demo

15 minutes to set up. 15 insights of what agents read about you, and 15 days to improve. If you do not see the value, you walk away with 15 better pages.