docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

feat(content-docs): allow autogenerated ID as fallback alias for explicit ID

Open fresh3nough opened this issue 8 months ago • 1 comments

Motivation

Closes #11691

When a document uses an explicit id in front matter, the autogenerated ID (derived from the file path) is completely replaced. This means any existing references that used the file-path-based ID break silently.

This PR proposes that the autogenerated ID be preserved as a fallback alias, so both the explicit ID and the file-path-based ID resolve to the same document.

Changes

  • Type: Added optional autoGeneratedId field to DocMetadataBase
  • Metadata: In doProcessDocMetadata, the file-path-based ID is computed and stored when the front matter id differs from the file name
  • Index: createDocsByIdIndex now registers autogenerated IDs as fallback entries (never overriding an explicit ID)
  • Tests: Added unit tests for autoGeneratedId computation and createDocsByIdIndex alias behavior
  • Snapshots: Updated 5 snapshots to reflect the new field on affected fixture docs

Test Plan

Ran the plugin test suite (docs.test.ts, index.test.ts, props.test.ts) - all 73 tests pass.

New tests cover:

  • Doc with explicit frontmatter ID different from filename gets autoGeneratedId
  • Doc with matching frontmatter ID has no autoGeneratedId
  • Doc without frontmatter ID has no autoGeneratedId
  • createDocsByIdIndex indexes by explicit ID
  • createDocsByIdIndex indexes by autoGeneratedId as fallback alias
  • autoGeneratedId alias never overrides an existing explicit ID

(AI-assisted)

fresh3nough avatar Mar 03 '26 14:03 fresh3nough

[V2]

Built without sensitive environment variables

Name Link
Latest commit 5b3507da931365337dd56b38022ca6ac283bca2d
Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69a6eb61d624e900081b3854
Deploy Preview https://deploy-preview-11769--docusaurus-2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify avatar Mar 03 '26 14:03 netlify