fix(docs): redirect integration sections to source - #3775
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces an automatic redirect for integration section pages to their corresponding "source" subpage within ".hugo/layouts/docs/section.html". The reviewer identified a potential Hugo build failure (nil pointer evaluation) that can occur if any page in ".Pages" does not have a physical file (where ".File" is nil). They provided a safer implementation that iterates through the pages, verifies ".File" is present, and avoids redundant index lookups.
| {{ $sourcePages := where .Pages "File.BaseFileName" "source" }} | ||
| {{ if and (hasPrefix .RelPermalink "/integrations/") (gt (len $sourcePages) 0) }} | ||
| <meta http-equiv="refresh" content="0; url={{ (index $sourcePages 0).RelPermalink }}"> | ||
| <script>window.location.replace({{ (index $sourcePages 0).RelPermalink | jsonify }});</script> | ||
| <p>Redirecting to <a href="{{ (index $sourcePages 0).RelPermalink }}">{{ (index $sourcePages 0).Title }}</a>...</p> | ||
| {{ else }} |
There was a problem hiding this comment.
Using where .Pages "File.BaseFileName" "source" can cause a Hugo build failure (nil pointer evaluation) if any page in .Pages does not have a physical file (i.e., .File is nil), which is common for virtual or auto-generated section pages.
Additionally, storing the matched page in a variable avoids repeating index $sourcePages 0 multiple times. We can safely find the source page by iterating and checking if .File is present.
{{ $sourcePage := "" }}
{{ range .Pages }}
{{ if and .File (eq .File.BaseFileName "source") }}
{{ $sourcePage = . }}
{{ end }}
{{ end }}
{{ if and (hasPrefix .RelPermalink "/integrations/") $sourcePage }}
<meta http-equiv="refresh" content="0; url={{ $sourcePage.RelPermalink }}">
<script>window.location.replace({{ $sourcePage.RelPermalink | jsonify }});</script>
<p>Redirecting to <a href="{{ $sourcePage.RelPermalink }}">{{ $sourcePage.Title }}</a>...</p>
{{ else }}|
🚀 Cloudflare Preview Ready! 🔎 View Preview: https://pr-3775.toolbox-docs-6xc.pages.dev (Note: Subsequent pushes to this PR will automatically update the preview at this same URL) |
|
Hi @lyydsheep thank you for your contribution. I was testing the |
Fixes #3752.
Integration sections that contain a
source.mdpage now redirect their root URL to that source page. This applies globally through the shared Hugo section layout, so new integrations inherit the behavior automatically.Validation:
sourcepage and emits both a meta refresh and JavaScript fallback.git diff --checkpasses.