Skip to content

check for circular aliases#25502

Merged
craig-osterhout merged 1 commit into
docker:mainfrom
craig-osterhout:circular-alias-check
Jul 24, 2026
Merged

check for circular aliases#25502
craig-osterhout merged 1 commit into
docker:mainfrom
craig-osterhout:circular-alias-check

Conversation

@craig-osterhout

@craig-osterhout craig-osterhout commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Added check for circular aliases.

I've done it a few times. Move something and add an alias. Then move it back and forget to remove the alias.

Currently there is a circular alias, so it should fail successfully.

Related issues or tickets

Reviews

  • Editorial review

@craig-osterhout
craig-osterhout requested a review from dvdksn July 6, 2026 20:09
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit 387c7fb
🔍 Latest deploy log https://app.netlify.com/projects/docsdocker/deploys/6a6380779564650008e617ab
😎 Deploy Preview https://deploy-preview-25502--docsdocker.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.

@github-actions github-actions Bot added area/release Relates to CI or deployment area/config area/tests ci ci updates labels Jul 6, 2026

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

The circular alias detection script is well-structured and integrates cleanly with the existing CI pipeline. The logic correctly identifies self-referential aliases across both manuals/ and standard Hugo paths. One minor latent risk noted inline.

Comment thread hack/test/validate_aliases Outdated

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟡 NEEDS ATTENTION

Comment thread hack/test/validate_aliases Outdated
@craig-osterhout craig-osterhout added the status/review Pull requests that are ready for review label Jul 6, 2026

@dvdksn dvdksn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey, I noticed this PR only now. I think there is a better way to detect these. We already process the aliases in the home.redirects.json template. As part of generating the redirects.json file, we could have hugo compare aliases and permalink, and errorf if there's a conflict. Something like:

 {{- range hugo.Sites -}}
   {{- range .Pages -}}
     {{- if .Params.aliases -}}
+      {{- $page := . -}}
       {{- $target := .RelPermalink -}}
       {{- range .Params.aliases -}}
-        {{ $redirects.SetInMap "paths" . $target }}
+        {{- $alias := . -}}
+        {{- if eq (strings.TrimSuffix "/" $alias) (strings.TrimSuffix "/" $target) -}}
+          {{- errorf "alias %q in %s resolves to the page itself" $alias $page.File.Path -}}
+        {{- end -}}
+        {{- $redirects.SetInMap "paths" $alias $target -}}
       {{- end -}}
     {{- end -}}
   {{- end -}}
 {{- end -}}

@github-actions github-actions Bot added the hugo Updates related to hugo label Jul 23, 2026
@craig-osterhout
craig-osterhout requested a review from dvdksn July 23, 2026 22:15
@craig-osterhout

craig-osterhout commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

That took me way longer than it should of to realize that it fails the netlify check and not the build one.
Looks like it's working.
https://app.netlify.com/projects/docsdocker/deploys/6a62921881577c0008738802

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

The PR adds a build-time self-referential alias check to the Hugo redirect template. The logic is sound for this repo's alias conventions (all aliases use leading slashes, matching 's format), so the equality check after stripping trailing slashes is effective.

No issues found in the changed code.

Signed-off-by: Craig Osterhout <craig.osterhout@docker.com>
@craig-osterhout
craig-osterhout merged commit 1fe539c into docker:main Jul 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config area/release Relates to CI or deployment area/tests ci ci updates hugo Updates related to hugo status/review Pull requests that are ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants