layouts: generate Netlify redirects from page aliases frontmatter#55310
layouts: generate Netlify redirects from page aliases frontmatter#55310Smeet23 wants to merge 1 commit intokubernetes:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
Welcome @Smeet23! |
Update layouts/index.redirects to iterate all site pages and emit server-side Netlify redirect lines for each alias declared in page frontmatter. This allows content authors and localization teams to manage redirects directly via the aliases field without editing the central static/_redirects.base file. Implementation details: - Collects all RegularPages permalinks for conflict detection - Resolves relative aliases using path.Dir of the page's RelPermalink - Emits a warnf and skips any alias conflicting with a real page URL - Localized aliases are fully supported; they appear in production builds where all language segments are rendered
2bcf5ba to
971132e
Compare
✅ Pull request preview available for checkingBuilt without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Pull request preview available for checkingBuilt without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
What this does
Updates
layouts/index.redirectsto auto-generate Netlify server-side redirects from thealiasesfield in page frontmatter, fixing #53396.Before this change, every redirect had to be manually added to
static/_redirects.base. After this change, content authors can declare:```yaml
aliases:
```
...and the redirect is automatically emitted into the generated
_redirectsfile at build time.How it works
.Site.RegularPagespermalinks into a slice for conflict detection.Site.Pages, reads each page'saliasesfrontmatterpath.Dir(matching Hugo's own alias resolution behavior)warnfguard catches any alias that conflicts with an existing real page permalink and skips it<alias> <page.RelPermalink> 301Testing
Built and verified locally:
/rbac/,/cve/,/cves/,/security/,master-node-communication,/dockershim) all appear correctly in the generated_redirectsmaster-node-communicationresolves to the correct sibling path (/docs/concepts/architecture/master-node-communication/) not as a child of the page/zh-cn/rbac/,/ru/security/, etc.) are present in their respective content files and will appear in the production build (which renders all language segments, unlike local dev which uses--renderSegments en)_redirects.baseare unaffectedFixes #53396