Skip to content

layouts: generate Netlify redirects from page aliases frontmatter#55310

Open
Smeet23 wants to merge 1 commit intokubernetes:mainfrom
Smeet23:fix/netlify-aliases-redirects
Open

layouts: generate Netlify redirects from page aliases frontmatter#55310
Smeet23 wants to merge 1 commit intokubernetes:mainfrom
Smeet23:fix/netlify-aliases-redirects

Conversation

@Smeet23
Copy link
Copy Markdown

@Smeet23 Smeet23 commented Apr 10, 2026

What this does

Updates layouts/index.redirects to auto-generate Netlify server-side redirects from the aliases field 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:

  • /old-url/
    ```

...and the redirect is automatically emitted into the generated _redirects file at build time.

How it works

  • First pass: collects all .Site.RegularPages permalinks into a slice for conflict detection
  • Second pass: iterates all .Site.Pages, reads each page's aliases frontmatter
  • Relative aliases are resolved against the page's parent directory using path.Dir (matching Hugo's own alias resolution behavior)
  • A warnf guard catches any alias that conflicts with an existing real page permalink and skips it
  • Valid aliases emit: <alias> <page.RelPermalink> 301

Testing

Built and verified locally:

  • English aliases (/rbac/, /cve/, /cves/, /security/, master-node-communication, /dockershim) all appear correctly in the generated _redirects
  • Relative alias master-node-communication resolves to the correct sibling path (/docs/concepts/architecture/master-node-communication/) not as a child of the page
  • No conflict warnings produced during build
  • Localized aliases (/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)
  • Existing static redirects in _redirects.base are unaffected

Fixes #53396

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 10, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sayakmukhopadhyay for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the sig/docs Categorizes an issue or PR as relevant to SIG Docs. label Apr 10, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 10, 2026

CLA Not Signed

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @Smeet23!

It looks like this is your first PR to kubernetes/website 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/website has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 10, 2026
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
@Smeet23 Smeet23 force-pushed the fix/netlify-aliases-redirects branch from 2bcf5ba to 971132e Compare April 10, 2026 18:26
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 10, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 10, 2026

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 2bcf5ba
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-io-main-staging/deploys/69d93e43d2ad060008ed86f4
😎 Deploy Preview https://deploy-preview-55310--kubernetes-io-main-staging.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
Copy link
Copy Markdown

netlify bot commented Apr 10, 2026

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 971132e
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-io-main-staging/deploys/69d940dcfed603000828cc06
😎 Deploy Preview https://deploy-preview-55310--kubernetes-io-main-staging.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.

Copy link
Copy Markdown
Member

@Arhell Arhell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/easycla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render Netlify redirects from page aliases

4 participants