From edcb3654d1affacc0e48df4001501551013e8cc5 Mon Sep 17 00:00:00 2001 From: sbegin0 Date: Tue, 1 Apr 2025 15:33:34 -0400 Subject: [PATCH 1/9] initial netlify edge functions commit/test --- .gitignore | 3 +++ netlify.toml | 4 ++++ netlify/edge-functions/redirect-to-latest.ts | 14 ++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 netlify/edge-functions/redirect-to-latest.ts diff --git a/.gitignore b/.gitignore index 97cc35437d99..06c01bc160de 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ go/** # archived site version archived_version + +# Local Netlify folder +.netlify diff --git a/netlify.toml b/netlify.toml index 9458eae5cfa0..99662359d9dc 100644 --- a/netlify.toml +++ b/netlify.toml @@ -14,3 +14,7 @@ [headers.values] X-Frame-Options = "SAMEORIGIN" X-XSS-Protection = "1; mode=block" + +[[edge_functions]] + path = "/v*" + function = "redirect-to-latest" \ No newline at end of file diff --git a/netlify/edge-functions/redirect-to-latest.ts b/netlify/edge-functions/redirect-to-latest.ts new file mode 100644 index 000000000000..883d63da064b --- /dev/null +++ b/netlify/edge-functions/redirect-to-latest.ts @@ -0,0 +1,14 @@ +export default async (request: Request) => { + const url = new URL(request.url); + + // Match paths starting with "/v" followed by a version number pattern + // Excludes paths containing "/docs/" + if (url.pathname.match(/^\/v\d+(\.\d+)*(\/|$)/) && !url.pathname.includes('/docs/')) { + // Preserve the rest of the path after the version part + const newPath = url.pathname.replace(/^\/v\d+(\.\d+)*/, '/latest'); + + return Response.redirect(new URL(newPath, url.origin), 301); + } + + return fetch(request); +}; \ No newline at end of file From 75a29601f0976093963fbffe30c7e09878e5a679 Mon Sep 17 00:00:00 2001 From: sbegin0 Date: Tue, 1 Apr 2025 18:25:45 -0400 Subject: [PATCH 2/9] updated regex for edge function ts --- netlify/edge-functions/redirect-to-latest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/edge-functions/redirect-to-latest.ts b/netlify/edge-functions/redirect-to-latest.ts index 883d63da064b..9a932614df39 100644 --- a/netlify/edge-functions/redirect-to-latest.ts +++ b/netlify/edge-functions/redirect-to-latest.ts @@ -3,7 +3,7 @@ export default async (request: Request) => { // Match paths starting with "/v" followed by a version number pattern // Excludes paths containing "/docs/" - if (url.pathname.match(/^\/v\d+(\.\d+)*(\/|$)/) && !url.pathname.includes('/docs/')) { + if (url.pathname.match(/^\/v\d+(\.\d+)*/) && !url.pathname.includes('/docs/')) { // Preserve the rest of the path after the version part const newPath = url.pathname.replace(/^\/v\d+(\.\d+)*/, '/latest'); From 80d8e0eef114adf1b5bb38acea8e6c589321b133 Mon Sep 17 00:00:00 2001 From: sbegin0 Date: Mon, 12 May 2025 17:44:58 -0400 Subject: [PATCH 3/9] first attempt at adding version selector dropdown to documentation --- data/versions.yml | 25 ++++++++- layouts/partials/header.html | 101 +++++++++++++++++++++++++++++++++-- 2 files changed, 121 insertions(+), 5 deletions(-) diff --git a/data/versions.yml b/data/versions.yml index f7d6363f23c8..4b46c80e4e06 100644 --- a/data/versions.yml +++ b/data/versions.yml @@ -1,5 +1,26 @@ -# The version of Istio currently documented in istio.io main: "1.26" -# The version of Istio currently documented in preliminary.istio.io preliminary: "1.27" + +# List of all versions to be included in the dropdown selector and for archive logic +versions: + - id: "1.26" # Version number + path_segment: latest # URL path for this version on istio.io + display_name: "v1.26 (Latest)" # Text in dropdown + status: latest # Status identifier + - id: "1.25" + path_segment: v1.25 # URL path for this archived version + display_name: "v1.25" + status: archive + - id: "1.24" + path_segment: v1.24 + display_name: "v1.24" + status: archive + - id: "1.23" + path_segment: v1.23 + display_name: "v1.23" + status: archive + - id: "1.22" + path_segment: v1.22 + display_name: "v1.22" + status: archive \ No newline at end of file diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 0261274a9050..f128befbf48c 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,6 +1,16 @@ {{ $home := .Site.GetPage "home" }} -{{ $section := .Section }} -{{ $current := . }} + +{{/* --- Version Logic (needed for JS and conditional dropdown) --- */}} +{{ $versionsData := site.Data.versions }} +{{ $currentVersionIDFromParams := .Site.Params.currentVersionId | default ($versionsData.latest_version | default "") }} +{{ $latestVersionID := $versionsData.latest_version | default "" }} +{{ $isLatestBuild := eq $currentVersionIDFromParams $latestVersionID }} +{{ $isDocsPage := eq .Section "docs" }} + +{{/* Calculate currentPathSegment - needed by navigateToVersionSimple JS function */}} +{{ $currentPathSegment := "" }} +{{ range $versionsData.versions }}{{ if eq .id $currentVersionIDFromParams }}{{ $currentPathSegment = .path_segment }}{{ end }}{{ end }} + + + \ No newline at end of file From 7824d92d99358172bf0db47d121d42a5e32e4f02 Mon Sep 17 00:00:00 2001 From: sbegin0 Date: Mon, 12 May 2025 17:47:19 -0400 Subject: [PATCH 4/9] removed console logs --- layouts/partials/header.html | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/layouts/partials/header.html b/layouts/partials/header.html index f128befbf48c..a83a6a4afe08 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -4,8 +4,6 @@ {{ $versionsData := site.Data.versions }} {{ $currentVersionIDFromParams := .Site.Params.currentVersionId | default ($versionsData.latest_version | default "") }} {{ $latestVersionID := $versionsData.latest_version | default "" }} -{{ $isLatestBuild := eq $currentVersionIDFromParams $latestVersionID }} -{{ $isDocsPage := eq .Section "docs" }} {{/* Calculate currentPathSegment - needed by navigateToVersionSimple JS function */}} {{ $currentPathSegment := "" }} @@ -111,15 +109,8 @@ const currentVersionPathSegment = {{ $currentPathSegment | jsonify }}; const selectedTargetSegment = selectedVersionPathSegment; - console.log("--- Version Navigation (Menu) ---"); - console.log("Current Full Path:", currentFullPath); - console.log("Current Version Segment (from Hugo):", currentVersionPathSegment); - console.log("Selected Target Segment:", selectedTargetSegment); - if (!currentVersionPathSegment && currentVersionPathSegment !== "" ) { - console.error("CRITICAL: Could not determine current version path segment. Aborting reliable navigation."); const fallbackBase = selectedTargetSegment === 'latest' ? '/latest/' : ('/' + selectedTargetSegment + '/'); - console.warn("Attempting fallback navigation to:", fallbackBase); window.location.href = fallbackBase; return; } @@ -132,7 +123,6 @@ const index = currentFullPath.indexOf('/' + prefix); if (index > -1) { contentPath = currentFullPath.substring(index + 1); - console.log("Found known prefix '" + prefix + "'. Determined Content Path:", contentPath); foundContent = true; break; } @@ -142,9 +132,7 @@ const currentBaseForCheck = currentVersionPathSegment === 'latest' ? '/latest/' : '/' + currentVersionPathSegment + '/'; if (currentFullPath === '/' || currentFullPath === currentBaseForCheck || currentFullPath === currentBaseForCheck.slice(0,-1)) { contentPath = ''; - console.log("Current path is a version root. Navigating to target version root/docs root."); } else { - console.warn("WARN: Could not find known content prefix in path '" + currentFullPath + "'. Navigating to target version's docs root."); contentPath = 'docs/'; // Default to docs root of target version } } @@ -161,8 +149,6 @@ let finalUrl = newBase + contentPath; finalUrl = finalUrl.replace(/\/\//g, '/'); // Replace double slashes - console.log("Attempting navigation to:", finalUrl); window.location.href = finalUrl; - console.log("--- End Version Navigation (Menu) ---"); } \ No newline at end of file From 1b55cc47bbd34ce09ce5bc59cef403bcc61ea09a Mon Sep 17 00:00:00 2001 From: sbegin0 Date: Tue, 13 May 2025 14:04:21 -0400 Subject: [PATCH 5/9] refined logic to programmatically decrement versions, removed netlify stuff --- data/versions.yml | 23 ------ layouts/partials/header.html | 85 ++++++++++++++------ netlify.toml | 4 - netlify/edge-functions/redirect-to-latest.ts | 14 ---- 4 files changed, 62 insertions(+), 64 deletions(-) delete mode 100644 netlify/edge-functions/redirect-to-latest.ts diff --git a/data/versions.yml b/data/versions.yml index 4b46c80e4e06..3778b9715420 100644 --- a/data/versions.yml +++ b/data/versions.yml @@ -1,26 +1,3 @@ main: "1.26" preliminary: "1.27" - -# List of all versions to be included in the dropdown selector and for archive logic -versions: - - id: "1.26" # Version number - path_segment: latest # URL path for this version on istio.io - display_name: "v1.26 (Latest)" # Text in dropdown - status: latest # Status identifier - - id: "1.25" - path_segment: v1.25 # URL path for this archived version - display_name: "v1.25" - status: archive - - id: "1.24" - path_segment: v1.24 - display_name: "v1.24" - status: archive - - id: "1.23" - path_segment: v1.23 - display_name: "v1.23" - status: archive - - id: "1.22" - path_segment: v1.22 - display_name: "v1.22" - status: archive \ No newline at end of file diff --git a/layouts/partials/header.html b/layouts/partials/header.html index a83a6a4afe08..df079df1d585 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,14 +1,16 @@ {{ $home := .Site.GetPage "home" }} -{{/* --- Version Logic (needed for JS and conditional dropdown) --- */}} -{{ $versionsData := site.Data.versions }} -{{ $currentVersionIDFromParams := .Site.Params.currentVersionId | default ($versionsData.latest_version | default "") }} -{{ $latestVersionID := $versionsData.latest_version | default "" }} - -{{/* Calculate currentPathSegment - needed by navigateToVersionSimple JS function */}} -{{ $currentPathSegment := "" }} -{{ range $versionsData.versions }}{{ if eq .id $currentVersionIDFromParams }}{{ $currentPathSegment = .path_segment }}{{ end }}{{ end }} - +{{/* --- Version Logic --- */}} +{{ $mainVersionFromYaml := site.Data.versions.main }} +{{ $currentBuildVersionId := .Site.Params.currentVersionId | default $mainVersionFromYaml }} +{{ $isLatestBuild := eq $currentBuildVersionId $mainVersionFromYaml }} + +{{ $currentPathSegmentForJS := "" }} +{{ if $isLatestBuild }} + {{ $currentPathSegmentForJS = "latest" }} +{{ else }} + {{ $currentPathSegmentForJS = printf "v%s" $currentBuildVersionId }} +{{ end }}