FFFF nx/astro-docs at master · abd1rahmane/nx · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
 
 

astro-docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Nx Documentation Site

Built with Starlight

The Nx documentation site built with Astro and Starlight, featuring advanced content management through Markdoc and dynamic plugin documentation generation.

Architecture Overview

This documentation site leverages Astro's static site generation capabilities with Starlight for documentation-specific features. The architecture consists of:

Core Technologies

  • Astro - Static site generator with island architecture
  • Starlight - Documentation theme with built-in navigation, search, and i18n
  • React - For implementing UI components
  • Netlify - Deployment and hosting

Key Features

  • Markdoc with custom tags for rich content such as videos, graphs, etc.
  • TailwindCSS for styling in Astro and React components
  • Dynamic API documentation generation from Nx packages and CLI commands
  • Community plugin registry

Information Architecture Principles

When creating or reorganizing documentation, follow these 6 principles to determine where content belongs.

1. Progressive Disclosure (The "Journey" Rule)

  • Concept: Don't overwhelm the user. Reveal complexity only as they advance in their journey.
  • The Test: Is this for the First 30 Minutes (Getting Started), the First 30 Days (Features), or Forever (Reference)?

2. Category Homogeneity (The "Scan" Rule)

  • Concept: Items in a list must be of the same "type" (noun, verb, or concept) to reduce cognitive load.
  • The Test: Does this list mix Concepts (Mental Model), Tasks (Update Nx), and Products (React)? If yes, split it.

3. Type-Based Navigation (The "Intent" Rule)

  • Concept: Separate Learning (Narrative/Guides) from Looking Up (Reference/API).
  • The Test: Is the user here to learn a workflow (Guide) or look up a flag syntax (Reference)?

4. Universal vs. Specific (The "Placement" Rule)

  • Concept: Distinguish Core features from Ecosystem tools to prevent "Features" from becoming a junk drawer.
  • The Test: Does this feature apply to EVERY user (e.g., Caching, Agents)?
  • Yes: Core features, or CI features when it only applies in CI.
  • No (Only React users): Technologies.

5. The Golden Path (The "One Way" Rule)

  • Concept: Feature pages teach the default workflow. Limit flags and variants to the ones a reader needs to make a decision.
  • The Test: Would a first-time user need this sentence to succeed or to choose? If not, it belongs in the corresponding Knowledge Base guide.

6. One Page Per Feature (The "Don't Make Me Hunt" Rule)

  • Concept: A feature page answers most of what a new reader arrives with. Specifics fan out to Knowledge Base guides, the questions stay on the page.
  • The Test: List the questions a new reader, or an AI answering for one, would ask about this feature. Does any answer live only on another page?
  • Counterweight to rule 5: Trim variants and edge cases, keep every question a reader has to answer before they can choose or start.

Sidebar Structure

The sidebar has 4 top-level sections that follow the user journey:

  1. Getting Started - Essential setup, tutorials, Core features, and CI features
  2. Technologies - Framework and tool-specific guides (React, Angular, Node, build tools, test tools)
  3. Knowledge Base - Recipes, troubleshooting, and topic-specific guides
  4. Reference - Exhaustive facts, no narrative (CLI commands, configuration, API docs)

Project Structure

astro-docs/
├── src/
│   ├── assets/          # Images and static assets to be optimized by Astro
│   │   ├── nx/          # Nx branding assets
│   │   ├── nx-cloud/    # Nx Cloud assets
│   │   └── nx-console/  # Nx Console assets
│   ├── components/      # React and Astro components
│   │   ├── layout/      # Layout components (e.g. Sidebar)
│   │   ├── markdoc/     # Markdoc tag components
│   │   └── utils/       # Utility functions
│   ├── content/         # Documentation content
│   │   ├── banner.json  # Banner collection (generated by prebuild-banner)
│   │   ├── docs/        # Main documentation files (.mdoc, .mdx)
│   │   └── approved-community-plugins.json  # Powers plugin registry
│   ├── pages/           # Dynamic pages and routes (e.g. devkit)
│   ├── plugins/         # Content loaders and plugins
│   │   ├── *.loader.ts  # Dynamic content loaders (e.g. CLI commands and API docs generation)
│   │   └── utils/       # Plugin utilities
│   └── styles/          # Global styles
├── public/              # Static assets not to be optimized by Astro (fonts, robots.txt)
├── astro.config.mjs     # Astro configuration
├── markdoc.config.mjs   # Markdoc tags configuration
├── sidebar.mts          # Sidebar structure definition
└── package.json

Plugins and Loaders

Content Loaders

The site uses custom content loaders to dynamically generate documentation:

  • PluginLoader (plugin.loader.ts) - Generates official plugin documentation (generators, executors, migrations)
  • CommunityPluginsLoader (community-plugins.loader.ts) - Generates data for plugin registry (e.g. GitHub stars, npm downloads)
  • NxReferencePackagesLoader (nx-reference-packages.loader.ts) - Generated data for CNW, Devkit, nx cli (e.g. nx core related things)
  • NxCloudPublicApiLoader (nx-cloud-public-api.loader.ts) - Generates the Public API reference from the deployed OpenAPI specification.

Nx Cloud Public API reference

The reference at /docs/reference/nx-cloud/public-api uses one model in src/plugins/nx-cloud-public-api/ for the Astro page, Markdown, copy content, and AI exports. Edit API descriptions in the upstream OpenAPI source and usage guides in src/content/docs/kb/.

The loader fetches https://cloud.nx.app/nx-cloud/data/openapi.json on each content sync. Set NX_CLOUD_OPENAPI_URL to use another deployment. Fetch or parse errors fail the sync instead of publishing stale documentation.

The build uses scripts/hash-openapi-spec.mjs as a runtime input. Specification changes invalidate the Nx cache without a repository change.

Content Management

Content Types

  1. Regular Documentation (src/content/docs/)

    • Written in .mdoc (Markdoc) or .mdx (MDX) format
    • Organized by sections: getting-started, concepts, guides, api
    • File-based routing (filename = URL path)
  2. Dynamic Plugin Documentation

    • Auto-generated from Nx packages
    • Includes generators, executors, and migrations
    • Updated during build process
    • Note: Requires a rebuild and restart to reflect changes
  3. CLI Documentation

    • Auto-generated from Nx CLI commands
    • Parsed from actual CLI implementation
    • Note: Requires a rebuild and restart to reflect changes

Markdoc Tags

The site includes custom Markdoc tags for rich content.

Note: Starlight supports many Markdown and Markdoc features, such as code blocks, asides, etc.

Layout & Organization

  • {% aside %} - Highlighted information boxes
  • {% cardgrid %}, {% card|linkcard %} - Card layouts
  • {% tabs %}, {% tabitem label="some-label" %} - Tab layouts
    • Use the syncKey so tabs are auto switched to the users preference if it makes sense.
    • e.g. {% tabs syncKey="package-manager" %}

Interactive Components

  • {% graph %} - Interactive project/task graph visualization
  • {% project_details %} - Project configuration viewer

Media & Embeds

  • {% youtube %} - YouTube video embeds
  • {% video_player %} - Custom video player
  • {% iframe %} - Generic iframe embeds

Developer Tools

  • {% github_repository %} - GitHub repo cards
  • {% stackblitz_button %} - StackBlitz demo launcher
  • {% install_nx_console %} - IDE extension installer

Content Enhancement

  • {% badge %} - Status/label pills
  • {% metrics %} - Metrics display
  • {% testimonial %} - Customer testimonials

Development Workflow

Getting Started

# Install dependencies and link workspace packages
# This will build Nx packages as well for API docs
nx serve astro-docs

# Or run astro dev directly
# This will not build Nx packages
cd astro-docs
npx astro dev

# Custom ports (useful for AI agents with git worktrees)
npx astro dev --port 3000

Running browser tests

Run pnpm nx pw-e2e astro-docs to test the development server. Run pnpm nx e2e-ci astro-docs to test the built site with the preview server. Both servers use a two-minute readiness timeout for /docs. The check follows redirects and requires a final 2xx response. It verifies the URL's response and does not identify the process serving it.

For direct Playwright invocation, start the local server first, then run pnpm exec playwright test --config astro-docs/playwright.config.ts. Global setup retains the same two-minute readiness check for this workflow. Each HTTP request has a five-second deadline.

BASE_URL changes the browser destination only. Both Nx and direct Playwright invocations still require http://localhost:4321/docs, including when BASE_URL points to a deployment. Start the local server on port 4321 for these tests.

Adding New Content

Regular Documentation

  1. Create .mdoc file in src/content/docs/
  2. Add frontmatter with title and description
  3. Use Markdoc tags for rich content
  4. File location determines URL structure

Example:

---
title: 'My New Guide'
description: 'Learn how to use this feature'
---

# Introduction

{% aside type="note" title="Important" %}
This is a note about the feature.
{% /aside %}

Adding Custom Markdoc Tags

  1. Create Astro component in src/components/markdoc/
  2. (Optional) Create React component for more complex components, or ones that need to be shared with blog or non-docs pages
  3. Register in markdoc.config.mjs
  4. Define attributes and validation

Updating Plugin Documentation

Plugin documentation is auto-generated during build. To update:

  1. Make changes to the plugin's schema/implementation
  2. Run the build process
  3. The loader will automatically fetch and generate updated docs

Sidebar Management

The sidebar structure is defined in sidebar.mts. To add new sections:

export const sidebar = [
  {
    label: 'Section Name',
    items: [
      {
        label: 'Page Title',
        link: 'path/to/page',
      },
      // Nested sections
      {
        label: 'Subsection',
        collapsed: true,
        items: [...]
      }
    ]
  }
];

Note there is a special case for sidebar items appearing in the sidebar. Such as the Reference section which is handled via the [sidebar-reference-updater](./src/plugins/sidebar-reference-updater.middleware.ts) middleware.

Styling and Theming

  • Uses Tailwind CSS v4 with Vite plugin
  • Global styles in src/styles/global.css
  • Component-specific styles use Tailwind utilities
  • Dark/light mode support built into Starlight and customized in global.css

Nx brand

The docs follow the Nx brand guidelines, so nx.dev/docs reads as one site with nx.dev and the blog.

  • Colors: the brand ramps (--color-nx-neutral-*, --color-nx-primary-*, plus cloud, success, warning and danger) are defined in the @theme block of global.css. Tailwind's slate, gray, zinc, blue, sky, green, yellow, amber and red palettes point at them, so existing utility classes pick up the brand colors. The Starlight tokens (--sl-color-*) are set from the same ramps.
  • Fonts: Instrument Sans for text and Server Mono for code, served from public/fonts.
  • Code blocks: themes and surfaces are set in ec.config.mjs.
  • Header and footer: src/components/layout/Header.astro and src/components/layout/site-nav/ are hand-built copies of the nx.dev (Framer) navbar and footer, shared with the blog (nrwl/nx-blog). They are always dark, like nx.dev. The header keeps the docs' own arrangement: logo, version switcher and the whole nav on the left (in line with the sidebar), search, the GitHub star count and the theme toggle on the right, with no "Get Started" pill. The theme toggle shows the active theme's icon and expands on hover or focus. The footer leaves out nx.dev's animated rays. When the Framer navbar or footer changes, update these and the blog together.
  • The header is 80px tall (64px below 50rem), set through --sl-nav-height. Below 50rem the nx.dev nav moves to the end of the sidebar menu.

Configuration Files

astro.config.mjs

  • Site configuration
  • Integration setup (React, Markdoc, Starlight)
  • Vite plugins
  • Build options

markdoc.config.mjs

  • Custom tag definitions
  • Attribute validation
  • Component mappings

sidebar.mts

  • Navigation structure
  • Section organization
  • Dynamic content injection points

Banner Configuration

The floating banner promotes events/webinars. It's fetched at build time from a Framer CMS page and stored as an Astro content collection.

Setup

Set BANNER_URL to point to a Framer page that renders banner JSON:

BANNER_URL=https://your-framer-site.framer.app/api/banners/main

The Framer page should render JSON inside a <pre> tag:

{
  "title": "Event Title",
  "description": "Event description",
  "primaryCtaUrl": "https://...",
  "primaryCtaText": "Learn More",
  "secondaryCtaUrl": "",
  "secondaryCtaText": "",
  "enabled": true,
  "activeUntil": "2025-12-31T00:00:00.000Z"
}

Schema

Field Type Required Description
title string Yes Banner headline
description string Yes Banner body text
primaryCtaUrl string Yes Primary button URL
primaryCtaText string Yes Primary button text
secondaryCtaUrl string No Secondary button URL
secondaryCtaText string No Secondary button text
enabled boolean Yes Show/hide the banner
activeUntil ISO 8601 No Auto-hide after this date

Behavior

  • Banner is fetched during prebuild-banner target and saved to src/content/banner.json as a collection (array)
  • Uses Astro content collection with file() loader and schema validation
  • Requires rebuild/redeploy to update the banner
  • Users can dismiss the banner (stored in localStorage)
  • If enabled is false or activeUntil has passed, the banner won't show
  • If BANNER_URL is not set, an empty collection is generated

Versioned Docs

When a new major Nx version is released (or about to be released), create a versioned snapshot of the docs site so the previous version remains accessible at {major}.nx.dev (e.g. 22.nx.dev).

Creating a Version Snapshot

node ./scripts/create-versioned-docs.mts 22

This will:

  1. Fetch tags from origin, find the latest stable release for that major (e.g. 22.6.4)
  2. Checkout that tag, install deps, and build the docs site
  3. Create an orphan git branch 22 containing only the pre-built static site plus minimal scaffolding (root package.json, nx.json, pnpm-lock.yaml, netlify.toml, and a no-op nx-dev project) so Netlify's configured build command succeeds instantly
  4. Return to your original branch

If no stable tags exist for that major version, it builds from the current branch.

For Nx 21+, the script builds astro-docs (Astro/Starlight). For legacy Nx 18–20, it builds nx-dev (Next.js with static export) — this path will be removed once those versions are no longer maintained.

Flags

  • --force — overwrite an existing local/remote {major} branch
  • --redirect-to-prod — skip the build and produce a branch that 301s every path to https://nx.dev/docs. Used to retire an old versioned subdomain (e.g. 16.nx.dev) without maintaining its docs
# Retire an old versioned site
node ./scripts/create-versioned-docs.mts 16 --redirect-to-prod

Pushing the Branch

git push -f origin 22

Deployment Setup

Versioned sites are served via Netlify branch deploys of the main nx-dev Netlify site, with custom domains managed in Squarespace.

  • Netlify — each {major} branch is deployed as a branch deploy of the nx-dev site. The branch's root netlify.toml overrides the UI build settings so Netlify serves the pre-built static files (no rebuild, no @netlify/plugin-nextjs). Add the branch to the site's branch deploy allowlist, then add {major}.nx.dev as a domain alias pointing at the branch deploy
  • Squarespace — DNS for nx.dev is managed in Squarespace. Add a CNAME for {major} pointing at the Netlify branch deploy hostname
0