Skip to content

Commit 5aa7985

Browse files
Updated Auto-Redirect Flow for Segments (#1339)
* CR-29590 * After review fix * swap commandbarSegment values for correct configuration * CR-29589 * docs: Exclude gitops collection pages from Sitemap.xml
1 parent 6dcd0ca commit 5aa7985

File tree

5 files changed

+159
-158
lines changed

5 files changed

+159
-158
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,21 @@ No actions required - the new content will be automatically reflected in both Ar
6464

6565
### Switching Between GitOps (ArgoHub) and Enterprise Segments
6666

67-
By default, users are redirected from the Enterprise segment to the GitOps (ArgoHub) segment.
67+
By default, users are redirected from the Enterprise segment to the GitOps (ArgoHub) segment.
6868

6969
#### Example:
70+
7071
- Accessing https://codefresh.io/docs/ will redirect to https://codefresh.io/docs/gitops/
7172

7273
For more details, refer to the "Auto Redirect from Enterprise to ArgoHub Collection" section below.
7374

74-
#### To switch segments in production:
75-
76-
- To switch to the GitOps segment, log in to Codefresh and switch to an account with the GitOps type. This will clear the Enterprise cookie.
77-
- To switch to the Enterprise segment, log in to Codefresh and switch to an account with any other type. This will set the Enterprise cookie.
78-
79-
#### To switch segments in local development:
75+
#### Switching Between Segments
8076

81-
In the local documentation site (`http://localhost:3131/`), open the console in developer tools and inject the appropriate cookie:
77+
- Use the segment dropdown menu in the page header to select a segment.
78+
- Use a cookie to automatically switch segments (production only):
8279

83-
- **Switch to Enterprise Segment:**
84-
```js
85-
document.cookie = 'cfdoctype=enterprise; SameSite=Strict; Domain=localhost; Max-age=2592000; Path=/';
86-
```
87-
88-
- **Switch to GitOps Segment:**
89-
```js
90-
document.cookie = 'cfdoctype=enterprise; SameSite=Strict; Domain=localhost; Max-age=0; Path=/';
91-
```
80+
- **To switch to the GitOps segment:** Log in to Codefresh and switch to an account with the GitOps type. This will set the GitOps cookie.
81+
- **To switch to the Enterprise segment:** Log in to Codefresh and switch to an account with any other type. This will clear the GitOps cookie.
9282

9383
### Reusing Existing Documents
9484

@@ -128,13 +118,26 @@ The ArgoHub home page and all pages within the ArgoHub collection are excluded f
128118

129119
- Commandbar HelpHub Search (managed via Commandbar Content Manager).
130120
- Search engines that support the `noindex` rule, such as Google.
121+
- All pages in the `gitops` collection, including the home page, are excluded from the Sitemap.xml file.
122+
123+
### Auto-Redirect: Enterprise to ArgoHub Collection
124+
125+
The documentation site automatically redirects users from any Enterprise page to the corresponding GitOps (ArgoHub) page when the GitOps cookie is present.
131126

132-
#### Commandbar's HelpHub and Copilot Content Sync
127+
#### Redirect Logic
133128

134-
Commandbar synchronizes the documentation site content using a crawler. However, the Auto Redirect mechanism prevents the crawler from accessing all Enterprise pages (see the "Auto Redirect from Enterprise to ArgoHub Collection" section for details). To address this issue, the Commandbar team configured the crawler to include the `cfdoctype` cookie, enabling it to access all documentation pages and bypass the redirect.
129+
```mermaid
130+
flowchart LR
131+
A[Enterprise Page] --> B{GitOps Cookie Present?}
132+
B -->|No| C[Stay on Enterprise Page]
133+
B -->|Yes| D[Redirect to GitOps Page]
134+
```
135135

136-
### Auto Redirect from Enterprise to ArgoHub Collection
136+
```mermaid
137+
flowchart LR
138+
A[GitOps Page] --> B[Stay on GitOps Page]
139+
```
137140

138-
When the GitOps client adds an ArgoHub system type cookie, the Documentation site will detect it and initiate an automatic redirect. If you open any page from the enterprise collection, the site will check for an equivalent document in the ArgoHub collection and redirect you there if one exists.
141+
#### Redirect Mapping
139142

140143
Redirect links between the Enterprise and ArgoHub collections are stored in the `argohub-redirect-mapping.json` file. Running `npm run link` automatically updates the file, eliminating the need for manual updates.

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ defaults:
129129
type: gitops
130130
values:
131131
layout: gitops
132+
sitemap: false
132133
toc: true
133134
wide: true
134135

_includes/scripts.html

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
<!-- End of Doc Search Embed Code -->
6060

6161
<script>
62-
const isEnterpriseDocumentationCookieSet = document.cookie.includes('cfdoctype=enterprise')
63-
const commandbarSegment = isEnterpriseDocumentationCookieSet ? '3033bf7f' : '43836ac3'
62+
const commandbarSegment = IS_GITOPS_DOC_COOKIE_SET ? '43836ac3': '3033bf7f'
6463

6564
var o=commandbarSegment,n=["Object.assign","Symbol","Symbol.for"].join("%2C"),a=window;function r(o,n){void 0===n&&(n=!1),"complete"!==document.readyState&&window.addEventListener("load",r.bind(null,o,n),{capture:!1,once:!0});var a=document.createElement("script");a.type="text/javascript",a.async=n,a.src=o,document.head.appendChild(a)}function t(){var n;if(void 0===a.CommandBar){delete a.__CommandBarBootstrap__;var t=Symbol.for("CommandBar::configuration"),e=Symbol.for("CommandBar::orgConfig"),i=Symbol.for("CommandBar::disposed"),c=Symbol.for("CommandBar::isProxy"),m=Symbol.for("CommandBar::queue"),d=Symbol.for("CommandBar::unwrap"),l=Symbol.for("CommandBar::eventSubscriptions"),s=[],u=localStorage.getItem("commandbar.lc"),f=u&&u.includes("local")?"http://localhost:8000":"https://api.commandbar.com",p=Object.assign(((n={})[t]={uuid:o},n[e]={},n[i]=!1,n[c]=!0,n[m]=new Array,n[d]=function(){return p},n[l]=void 0,n),a.CommandBar),b=["addCommand","boot","addEventSubscriber","addRecordAction","setFormFactor"],y=p;Object.assign(p,{shareCallbacks:function(){return{}},shareContext:function(){return{}}}),a.CommandBar=new Proxy(p,{get:function(o,n){return n in y?p[n]:"then"!==n?b.includes(n)?function(){var o=Array.prototype.slice.call(arguments);return new Promise((function(a,r){o.unshift(n,a,r),p[m].push(o)}))}:function(){var o=Array.prototype.slice.call(arguments);o.unshift(n),p[m].push(o)}:void 0}}),null!==u&&s.push("lc=".concat(u)),s.push("version=2"),r("".concat(f,"/latest/").concat(o,"?").concat(s.join("&")),!0)}}void 0===Object.assign||"undefined"==typeof Symbol||void 0===Symbol.for?(a.__CommandBarBootstrap__=t,r("https://polyfill.io/v3/polyfill.min.js?version=3.101.0&callback=__CommandBarBootstrap__&features="+n)):t();
6665
window.CommandBar.setThemeMode('dark_mode')
@@ -81,105 +80,3 @@
8180
}
8281
});
8382
</script>
84-
85-
<script>
86-
toggleSegmentDropdown = function() {
87-
const select = document.querySelector('.custom-select');
88-
select.classList.toggle('open');
89-
};
90-
91-
handleDropdownKeydown = function (event) {
92-
const select = document.querySelector('.custom-select');
93-
const options = select.querySelectorAll('.option');
94-
const isOpen = select.classList.contains('open');
95-
96-
switch (event.key) {
97-
case 'Enter':
98-
case ' ':
99-
event.preventDefault();
100-
toggleSegmentDropdown();
101-
break;
102-
case 'ArrowDown':
103-
event.preventDefault();
104-
if (!isOpen) toggleSegmentDropdown();
105-
options[0].focus();
106-
break;
107-
case 'Escape':
108-
if (isOpen) toggleSegmentDropdown();
109-
break;
110-
}
111-
};
112-
113-
handleOptionKeydown = function (event, option, selectedValue) {
114-
const select = document.querySelector('.custom-select');
115-
const options = select.querySelectorAll('.option');
116-
const currentIndex = Array.from(options).indexOf(option);
117-
118-
switch (event.key) {
119-
case 'Enter':
120-
case ' ':
121-
event.preventDefault();
122-
selectSegmentOption(option, selectedValue);
123-
break;
124-
case 'ArrowDown':
125-
event.preventDefault();
126-
if (currentIndex < options.length - 1) {
127-
options[currentIndex + 1].focus();
128-
}
129-
break;
130-
case 'ArrowUp':
131-
event.preventDefault();
132-
if (currentIndex > 0) {
133-
options[currentIndex - 1].focus();
134-
}
135-
break;
136-
case 'Escape':
137-
select.classList.remove('open');
138-
select.querySelector('.select-display').focus();
139-
break;
140-
}
141-
};
142-
143-
selectSegmentOption = async function (option, selectedValue) {
144-
const selectDisplay = document.querySelector('.select-display');
145-
146-
selectDisplay.textContent = option.textContent;
147-
148-
const redirectMap = await fetchRedirectMap();
149-
150-
const pathname = window.location.pathname;
151-
const currentPath = pathname.replace(SITE_BASE_URL, "");
152-
153-
if (selectedValue === 'enterprise') {
154-
localStorage.setItem(enterpriseDocTypeLockKey, 'true');
155-
156-
const enterprisePath = Object.keys(redirectMap).find(
157-
key => redirectMap[key] === currentPath
158-
);
159-
160-
if (enterprisePath) {
161-
window.location.href = `${SITE_BASE_URL}${enterprisePath}`;
162-
} else {
163-
window.location.href = `${SITE_BASE_URL}/`;
164-
}
165-
} else if (selectedValue === 'gitops') {
166-
localStorage.setItem(enterpriseDocTypeLockKey, 'false');
167-
168-
const gitOpsPath = redirectMap[currentPath];
169-
170-
if (gitOpsPath) {
171-
window.location.href = `${SITE_BASE_URL}${gitOpsPath}`;
172-
} else {
173-
window.location.href = `${SITE_BASE_URL}/${SITE_GITOPS_COLLECTION}/`;
174-
}
175-
}
176-
};
177-
// Close dropdown when clicking outside
178-
document.addEventListener('click', (e) => {
179-
const select = document.querySelector('.custom-select');
180-
if (!select.contains(e.target)) {
181-
select.classList.remove('open');
182-
}
183-
});
184-
</script>
185-

assets/js/src/argohub-redirect.js

Lines changed: 132 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,157 @@
1-
const enterpriseDocumentationCookie = "cfdoctype=enterprise";
2-
const ARGOHUB_MAIN_PATH = `/${SITE_GITOPS_COLLECTION}/`;
3-
const enterpriseDocTypeLockKey = "enterpriseDocTypeLock";
1+
const GITOPS_DOC_COOKIE = 'cfdoctype=gitops'
2+
const IS_GITOPS_DOC_COOKIE_SET = document.cookie.includes(GITOPS_DOC_COOKIE)
43

5-
function checkIfEnterpriseDocumentationCookieSet() {
6-
return document.cookie.includes(enterpriseDocumentationCookie);
7-
}
4+
handleRedirect()
85

96
async function getArgoHubRedirectURL(currentPath) {
10-
currentPath = currentPath.replace(SITE_BASE_URL, "");
7+
currentPath = currentPath.replace(SITE_BASE_URL, '')
118

12-
const redirectMap = await fetchRedirectMap();
9+
const redirectMap = await fetchRedirectMap()
1310

14-
const newPath = redirectMap[currentPath];
15-
if (!newPath) return null;
11+
const newPath = redirectMap[currentPath]
12+
if (!newPath) return null
1613

1714
const newURL =
18-
newPath === ARGOHUB_MAIN_PATH
15+
newPath === `/${SITE_GITOPS_COLLECTION}/`
1916
? `${location.href}${SITE_GITOPS_COLLECTION}`
20-
: location.href.replace(currentPath, newPath);
17+
: location.href.replace(currentPath, newPath)
2118

22-
return newURL;
19+
return newURL
2320
}
2421

2522
async function handleRedirect() {
26-
if (shouldSkipRedirect()) return;
23+
if (SITE_IS_GITOPS_COLLECTION || !IS_GITOPS_DOC_COOKIE_SET) return
2724

28-
const argoHubRedirectURL = await getArgoHubRedirectURL(location.pathname);
29-
if (!argoHubRedirectURL) return;
25+
const argoHubRedirectURL = await getArgoHubRedirectURL(location.pathname)
26+
if (!argoHubRedirectURL) return
3027

31-
location.href = argoHubRedirectURL;
28+
location.href = argoHubRedirectURL
3229
}
3330

3431
async function fetchRedirectMap() {
35-
const response = await fetch(
36-
`${SITE_BASE_URL}/assets/js/src/argohub-redirect-mapping.json`
37-
);
32+
const response = await fetch(`${SITE_BASE_URL}/assets/js/src/argohub-redirect-mapping.json`)
3833
if (!response.ok) {
39-
throw new Error("Failed to fetch the collections redirect map.");
34+
throw new Error('Failed to fetch the collections redirect map.')
35+
}
36+
return response.json()
37+
}
38+
39+
function setGitOpsDocumentationCookie() {
40+
const maxAge = 2592000
41+
configureGitOpsDocumentationCookie(maxAge)
42+
}
43+
44+
function removeGitOpsDocumentationCookie() {
45+
configureGitOpsDocumentationCookie(0)
46+
}
47+
48+
function configureGitOpsDocumentationCookie(maxAge) {
49+
let cookie = `${GITOPS_DOC_COOKIE}; Max-Age=${maxAge}; Path=/; SameSite=Strict`
50+
51+
if (location.protocol === 'https:') {
52+
cookie += '; Secure'
53+
}
54+
55+
if (location.hostname.endsWith('.codefresh.io')) {
56+
cookie += '; Domain=.codefresh.io'
57+
}
58+
59+
document.cookie = cookie
60+
}
61+
62+
function toggleSegmentDropdown() {
63+
const select = document.querySelector('.custom-select')
64+
select.classList.toggle('open')
65+
}
66+
67+
function handleDropdownKeydown(event) {
68+
const select = document.querySelector('.custom-select')
69+
const options = select.querySelectorAll('.option')
70+
const isOpen = select.classList.contains('open')
71+
72+
switch (event.key) {
73+
case 'Enter':
74+
case ' ':
75+
event.preventDefault()
76+
toggleSegmentDropdown()
77+
break
78+
case 'ArrowDown':
79+
event.preventDefault()
80+
if (!isOpen) toggleSegmentDropdown()
81+
options[0].focus()
82+
break
83+
case 'Escape':
84+
if (isOpen) toggleSegmentDropdown()
85+
break
4086
}
41-
return response.json();
4287
}
4388

44-
function isEnterpriseLockPresent() {
45-
const enterpriseDocTypeLock = localStorage.getItem(enterpriseDocTypeLockKey);
46-
return !!enterpriseDocTypeLock;
89+
function handleOptionKeydown(event, option, selectedValue) {
90+
const select = document.querySelector('.custom-select')
91+
const options = select.querySelectorAll('.option')
92+
const currentIndex = Array.from(options).indexOf(option)
93+
94+
switch (event.key) {
95+
case 'Enter':
96+
case ' ':
97+
event.preventDefault()
98+
selectSegmentOption(option, selectedValue)
99+
break
100+
case 'ArrowDown':
101+
event.preventDefault()
102+
if (currentIndex < options.length - 1) {
103+
options[currentIndex + 1].focus()
104+
}
105+
break
106+
case 'ArrowUp':
107+
event.preventDefault()
108+
if (currentIndex > 0) {
109+
options[currentIndex - 1].focus()
110+
}
111+
break
112+
case 'Escape':
113+
select.classList.remove('open')
114+
select.querySelector('.select-display').focus()
115+
break
116+
}
47117
}
48118

49-
function shouldSkipRedirect() {
50-
return true; // Redirect temporarily disabled. Will be re-enabled with a new cookie-based mechanism.
51-
// return (
52-
// isEnterpriseLockPresent() ||
53-
// SITE_IS_GITOPS_COLLECTION ||
54-
// checkIfEnterpriseDocumentationCookieSet()
55-
// );
119+
async function selectSegmentOption(option, selectedValue) {
120+
const selectDisplay = document.querySelector('.select-display')
121+
122+
selectDisplay.textContent = option.textContent
123+
124+
const redirectMap = await fetchRedirectMap()
125+
126+
const pathname = window.location.pathname
127+
const currentPath = pathname.replace(SITE_BASE_URL, '')
128+
129+
if (selectedValue === 'enterprise') {
130+
removeGitOpsDocumentationCookie()
131+
132+
const enterprisePath = Object.keys(redirectMap).find((key) => redirectMap[key] === currentPath)
133+
134+
if (enterprisePath) {
135+
window.location.href = `${SITE_BASE_URL}${enterprisePath}`
136+
} else {
137+
window.location.href = `${SITE_BASE_URL}/`
138+
}
139+
} else if (selectedValue === 'gitops') {
140+
setGitOpsDocumentationCookie()
141+
142+
const gitOpsPath = redirectMap[currentPath]
143+
144+
if (gitOpsPath) {
145+
window.location.href = `${SITE_BASE_URL}${gitOpsPath}`
146+
} else {
147+
window.location.href = `${SITE_BASE_URL}/${SITE_GITOPS_COLLECTION}/`
148+
}
149+
}
56150
}
57151

58-
handleRedirect();
152+
document.addEventListener('click', (e) => {
153+
const select = document.querySelector('.custom-select')
154+
if (!select.contains(e.target)) {
155+
select.classList.remove('open')
156+
}
157+
})

gitops/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: home
33
title: GitOps Home
4+
sitemap: false
45
---
56

67
<main class="bd-masthead bd-masthead-home" id="content" role="main">

0 commit comments

Comments
 (0)