Skip to content

Commit 78c7a98

Browse files
committed
fix(ci): add path offset for PR preview subdirectory baseURL
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).
1 parent 61a88db commit 78c7a98

5 files changed

Lines changed: 29 additions & 11 deletions

File tree

.github/workflows/pr-preview.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ jobs:
9090
PREVIEW_BASE_URL: https://influxdata.github.io/docs-v2/pr-preview/pr-${{ github.event.number }}/
9191
run: |
9292
START_TIME=$(date +%s)
93-
npx hugo --minify --baseURL "$PREVIEW_BASE_URL"
93+
# Use pr-preview environment for path offset config
94+
npx hugo --minify --baseURL "$PREVIEW_BASE_URL" -e pr-preview
9495
END_TIME=$(date +%s)
9596
DURATION=$((END_TIME - START_TIME))
9697
echo "build-time=${DURATION}s" >> $GITHUB_OUTPUT

config/pr-preview/params.yml

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

layouts/shortcodes/api-endpoint.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
2-
{{- $currentVersion := index $productPathData 1 -}}
2+
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
3+
{{- $pathOffset := .Site.Params.prPreviewPathOffset | default 0 -}}
4+
{{- $currentVersion := index $productPathData (add $pathOffset 1) -}}
35
{{- $endpoint := .Get "endpoint" -}}
46
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
57
{{- $parsedProductKey := cond $isOSS "oss" $currentVersion -}}
68
{{- $productKey := .Get "influxdb_host" | default $parsedProductKey -}}
79
{{- $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" -}}
810
{{- $productRef := index $productAliases $productKey -}}
9-
{{- $productData := index .Site.Data.products $productRef -}}
10-
{{- $placeholderHost := $productData.placeholder_host }}
11+
{{- $productData := dict -}}
12+
{{- with $productRef }}{{- $productData = index $.Site.Data.products . | default dict -}}{{- end -}}
13+
{{- $placeholderHost := $productData.placeholder_host | default "localhost:8086" }}
1114
{{- $method := .Get "method" | upper -}}
1215
{{- $methodStyle := .Get "method" | lower -}}
1316
{{- $apiRef := .Get "api-ref" | default "" -}}

layouts/shortcodes/children.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@
4242
{{ end }}
4343
{{ end }}
4444
{{ if .Params.list_code_example }}
45-
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
46-
{{- $currentVersion := index $productPathData 1 -}}
45+
{{- $productPathData := findRE "[^/]+.*?" $.Page.RelPermalink -}}
46+
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
47+
{{- $pathOffset := $.Site.Params.prPreviewPathOffset | default 0 -}}
48+
{{- $currentVersion := index $productPathData (add $pathOffset 1) -}}
4749
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
4850
{{- $productKey := cond $isOSS "oss" $currentVersion -}}
4951
{{- $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" -}}
5052
{{- $productRef := index $productAliases $productKey -}}
51-
{{- $productData := index .Site.Data.products $productRef -}}
52-
{{- $placeholderHost := $productData.placeholder_host }}
53+
{{- $productData := dict -}}
54+
{{- with $productRef }}{{- $productData = index $.Site.Data.products . | default dict -}}{{- end -}}
55+
{{- $placeholderHost := $productData.placeholder_host | default "localhost:8086" }}
5356
{{ .Params.list_code_example | replaceRE `\{\{[<\%] influxdb/host [>%]\}\}` $placeholderHost | .RenderString }}
5457
{{ end }}
5558

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
2-
{{- $currentVersion := index $productPathData 1 -}}
2+
{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}}
3+
{{- $pathOffset := .Site.Params.prPreviewPathOffset | default 0 -}}
4+
{{- $currentVersion := index $productPathData (add $pathOffset 1) -}}
35
{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
46
{{- $parsedProductKey := cond $isOSS "oss" $currentVersion -}}
57
{{- $productKey := .Get 0 | default $parsedProductKey -}}
68
{{- $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" -}}
79
{{- $productRef := index $productAliases $productKey -}}
8-
{{- $productData := index .Site.Data.products $productRef -}}
9-
{{ $productData.placeholder_host }}
10+
{{- $productData := dict -}}
11+
{{- with $productRef }}{{- $productData = index $.Site.Data.products . | default dict -}}{{- end -}}
12+
{{ $productData.placeholder_host | default "localhost:8086" }}

0 commit comments

Comments
 (0)