docusaurus
docusaurus copied to clipboard
feat(content-docs): allow autogenerated ID as fallback alias for explicit ID
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
autoGeneratedIdfield toDocMetadataBase - Metadata: In
doProcessDocMetadata, the file-path-based ID is computed and stored when the front matteriddiffers from the file name - Index:
createDocsByIdIndexnow registers autogenerated IDs as fallback entries (never overriding an explicit ID) - Tests: Added unit tests for
autoGeneratedIdcomputation andcreateDocsByIdIndexalias 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 createDocsByIdIndexindexes by explicit IDcreateDocsByIdIndexindexes byautoGeneratedIdas fallback aliasautoGeneratedIdalias never overrides an existing explicit ID
(AI-assisted)
[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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.