fix(ci): add path offset for PR preview subdirectory baseURL (#6662)

When PR preview builds use a subdirectory baseURL like
/docs-v2/pr-preview/pr-XXXX/, shortcodes that parse .RelPermalink
to detect product context fail because the path has extra segments.

This fix:
- Adds config/pr-preview/params.yml with prPreviewPathOffset: 3
- Updates workflow to use -e pr-preview environment
- Updates api-endpoint, influxdb/host, and children shortcodes to
  use the offset when indexing path segments
- Adds nil-safety with default fallback for placeholder_host

Normal builds are unaffected (offset defaults to 0).
pull/6666/head
Jason Stirnaman 2025-12-22 11:03:27 -05:00 committed by GitHub
parent 975132d2b9
commit 74c33e9483
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 11 deletions

View File

@ -90,7 +90,8 @@ jobs:
PREVIEW_BASE_URL: https://influxdata.github.io/docs-v2/pr-preview/pr-${{ github.event.number }}/
run: |
START_TIME=$(date +%s)
npx hugo --minify --baseURL "$PREVIEW_BASE_URL"
# Use pr-preview environment for path offset config
npx hugo --minify --baseURL "$PREVIEW_BASE_URL" -e pr-preview
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
echo "build-time=${DURATION}s" >> $GITHUB_OUTPUT

View File

@ -0,0 +1,8 @@
# PR Preview environment parameters
# Used when building with: npx hugo -e pr-preview
# Number of path segments to skip when parsing RelPermalink for product detection
# For baseURL like https://influxdata.github.io/docs-v2/pr-preview/pr-6657/
# The path has 3 extra segments: docs-v2, pr-preview, pr-XXXX
# Workaround to correctly detect products in preview builds for Hugo templates relying on relPermalink to set active product
prPreviewPathOffset: 3

View File

@ -1,13 +1,16 @@
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $currentVersion := index $productPathData 1 -}}
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
{{- $pathOffset := .Site.Params.prPreviewPathOffset | default 0 -}}
{{- $currentVersion := index $productPathData (add $pathOffset 1) -}}
{{- $endpoint := .Get "endpoint" -}}
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
{{- $parsedProductKey := cond $isOSS "oss" $currentVersion -}}
{{- $productKey := .Get "influxdb_host" | default $parsedProductKey -}}
{{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
{{- $productRef := index $productAliases $productKey -}}
{{- $productData := index .Site.Data.products $productRef -}}
{{- $placeholderHost := $productData.placeholder_host }}
{{- $productData := dict -}}
{{- with $productRef }}{{- $productData = index $.Site.Data.products . | default dict -}}{{- end -}}
{{- $placeholderHost := $productData.placeholder_host | default "localhost:8086" }}
{{- $method := .Get "method" | upper -}}
{{- $methodStyle := .Get "method" | lower -}}
{{- $apiRef := .Get "api-ref" | default "" -}}

View File

@ -42,14 +42,17 @@
{{ end }}
{{ end }}
{{ if .Params.list_code_example }}
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $currentVersion := index $productPathData 1 -}}
{{- $productPathData := findRE "[^/]+.*?" $.Page.RelPermalink -}}
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
{{- $pathOffset := $.Site.Params.prPreviewPathOffset | default 0 -}}
{{- $currentVersion := index $productPathData (add $pathOffset 1) -}}
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
{{- $productKey := cond $isOSS "oss" $currentVersion -}}
{{- $productAliases := dict "oss" "influxdb" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
{{- $productRef := index $productAliases $productKey -}}
{{- $productData := index .Site.Data.products $productRef -}}
{{- $placeholderHost := $productData.placeholder_host }}
{{- $productData := dict -}}
{{- with $productRef }}{{- $productData = index $.Site.Data.products . | default dict -}}{{- end -}}
{{- $placeholderHost := $productData.placeholder_host | default "localhost:8086" }}
{{ .Params.list_code_example | replaceRE `\{\{[<\%] influxdb/host [>%]\}\}` $placeholderHost | .RenderString }}
{{ end }}

View File

@ -1,9 +1,12 @@
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
{{- $currentVersion := index $productPathData 1 -}}
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
{{- $pathOffset := .Site.Params.prPreviewPathOffset | default 0 -}}
{{- $currentVersion := index $productPathData (add $pathOffset 1) -}}
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
{{- $parsedProductKey := cond $isOSS "oss" $currentVersion -}}
{{- $productKey := .Get 0 | default $parsedProductKey -}}
{{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
{{- $productRef := index $productAliases $productKey -}}
{{- $productData := index .Site.Data.products $productRef -}}
{{ $productData.placeholder_host }}
{{- $productData := dict -}}
{{- with $productRef }}{{- $productData = index $.Site.Data.products . | default dict -}}{{- end -}}
{{ $productData.placeholder_host | default "localhost:8086" }}