Skip to navigation
Additional Pages

Build the Documentation

View as MarkdownOpen in Claude

The published Megatron Core documentation is a Fern site. Fern compiles Markdown/MDX content and YAML configuration into a hosted static site. The content lives in docs/, and the Fern configuration lives in fern/.

Prerequisites

  • Node.js 22
  • The Fern CLI at the version pinned in fern/fern.config.json. Using the pinned version keeps local results consistent with CI.

Install the Fern CLI

From the repository root, install the pinned version of the CLI:

npm install -g "fern-api@$(jq -er .version fern/fern.config.json)"

Do not run fern init in this repository. The fern/ folder already exists and is configured. Run fern upgrade only when intentionally bumping the CLI pin in fern/fern.config.json.

Project Layout

PathPurpose
fern/fern.config.jsonIdentifies the Fern organization and pins the CLI version.
fern/docs.ymlSite manifest: docs URL, title, theme, navbar links, redirects, and versions.
fern/redirects.ymlRedirects from the legacy URLs to the Fern site.
fern/versions/The Archives version, which links to previous developer guides.
docs/index.ymlNavigation for the Nightly version (sidebar structure and page slugs).
docs/**/*.mdThe documentation pages.

The site has two versions: Nightly (the default, built from docs/) and Archives. Publishing tags select a Git revision.

Add or Edit a Page

  1. Create or edit a Markdown file under docs/. Start a new page with front matter:

    ---
    title: "Page Title"
    description: "Optional subtitle"
    ---
    Hello world!
  2. Register the page in docs/index.yml so it appears in the navigation. Paths are relative to docs/index.yml:

    navigation:
    - section: "Basic Usage"
    skip-slug: true
    contents:
    - page: "Hello World"
    path: ./user-guide/hello-world.md
    slug: hello-world

Fern supports GitHub flavored Markdown within MDX files. Pages are parsed as MDX, so escape or put in code spans any bare <, >, or { characters in prose. If you rename or move a page, add a rule to fern/redirects.yml for the old URL.

Validate the Documentation

Run the same checks as CI from the fern/ folder:

cd fern/
fern check
fern docs md check
fern docs broken-links --strict
  • fern check validates the Fern configuration.
  • fern docs md check validates the MDX content.
  • fern docs broken-links --strict fails on broken internal links.

Preview Locally

Run the local development server with hot reloading. The site updates as you edit Markdown and YAML files:

cd fern/
fern docs dev

Open the URL printed in the terminal (by default, http://localhost:3000) to view the site. If you use a remote machine, forward the port to your local machine.

fern docs dev cannot test redirects. Verify them on a shared preview deployment.

Share a Preview

You do not need to create previews manually for pull requests. Once a non-draft PR is synchronized to pull-request/<number>, CI validates the documentation and, after a reviewer approves the fern-preview deployment, posts a preview link on the PR. See fern/README.md for details.

To generate a shareable preview link manually, log in with fern login (or set FERN_TOKEN) and run:

cd fern/
fern generate --docs --preview

Publish

Publishing is handled by CI and requires approval. Do not publish from a local machine.

  • Pushes to main that change docs update the shared megatron-lm-staging preview.
  • Pushing a docs/v* tag, or manually running the fern-docs-publish.yml workflow, publishes production after validation and approval of the fern-publish environment.
  • When a final core_vX.Y.Z release is cut, a draft PR adds the release to fern/versions/archives.mdx.