web-unified-docs: how content is stored, processed, and served to the dev-portal frontend.
Content flow overview
- Documentation content is authored in the
/contentdirectory. - The prebuild process (
npm run prebuild) transforms that content into processed files in/public. - The Next.js API routes in
/app/apiread from/publicand serve content to the dev-portal via REST endpoints.
The two API systems
During the migration period, Dev Portal sources content from two APIs:Content API
content.hashicorp.com — the existing system. Sources documentation directly from individual product repositories. Powered by
hashicorp/mktg-content-workflows.Unified Docs API
This repository — the new system. Sources documentation from the
/content directory. Will eventually replace the content API entirely.Directory structure
The prebuild process
Before the API can serve content, the prebuild step must run. Inside the Docker container this happens automatically on startup. For local development outside Docker, run it manually:- Processes content — reads MDX files from
/contentand writes processed versions topublic/content. - Processes assets — copies image assets from
/contentintopublic/assets, organized by product and version. - Generates
docsPaths.json— a flat list of all known documentation paths, written toapp/api/docsPaths.json. Used by the/api/all-docs-pathsendpoint. - Generates
versionMetadata.json— version metadata for all versioned products, written toapp/api/versionMetadata.json. Used by the/api/content/[productSlug]/version-metadataendpoint.
Versioning approach
Unified docs uses directory-based versioning instead of the historic git branch and tag strategy. Each versioned product has a subdirectory per supported version:- You can update documentation for multiple versions in a single PR — just edit the files in the relevant version directories.
- Finding and applying the same change across versions is a simple find-and-replace on the filesystem.
- There is no need to cherry-pick commits across branches.
Version metadata
The prebuild process collects version metadata by scanning the version subdirectories in each product’s content folder. TheproductConfig.mjs file provides a semverCoerce function per product that normalizes version strings for sorting. Terraform Enterprise, for example, uses date-based version strings (v202206-01) rather than semver, so its semverCoerce function converts those to sortable semver values.
The Next.js API routes
All API routes live in/app/api and are implemented as Next.js Route Handlers. They serve the dev-portal and any other consumers that need documentation content.
| Route | Description |
|---|---|
GET /api/all-docs-paths | Returns all known documentation paths across all (or a filtered set of) products. Used by dev-portal to build its routing table. |
GET /api/content/[productSlug]/doc/[version]/[...path] | Returns the processed MDX content and metadata for a specific doc page. |
GET /api/content/[productSlug]/nav-data/[version]/[...section] | Returns navigation sidebar data for a product version. |
GET /api/content/[productSlug]/version-metadata | Returns available versions and version metadata for a product. |
GET /api/content/[productSlug]/redirects | Returns redirect rules defined in a product’s content directory. |
GET /api/assets/[productSlug]/[version]/[...path] | Serves image and other static assets for a product version. |
GET /api/content-versions | Returns the versions in which a specific document exists. |
GET /api/supported-products | Returns the list of all product slugs currently supported by the unified docs API. |
The unified docs API is designed as a drop-in replacement for the existing content API at
content.hashicorp.com. Routes are intentionally compatible with the existing API contract so the dev-portal can switch between them without frontend changes.