@@ -3,17 +3,38 @@ let newVersion = "";
3
3
let currentVersion = "" ;
4
4
let fileRequested = "" ;
5
5
6
+ // Get the base URL dynamically
7
+ function getBaseUrl ( ) {
8
+ const path = window . location . pathname ;
9
+ // Find the first directory in the path that matches one of our document types
10
+ const pathParts = path . split ( '/' ) . filter ( part => part . length > 0 ) ;
11
+
12
+ // If we're on a page like /logging/6.2/..., the first part is the docType
13
+ // and we should return everything up to that part including the hostname
14
+ if ( pathParts . length >= 1 ) {
15
+ // Create a URL that includes everything up to the docType directory
16
+ const baseUrl = `${ window . location . protocol } //${ window . location . host } /` ;
17
+ return baseUrl ;
18
+ }
19
+
20
+ // Fallback to current origin
21
+ return `${ window . location . protocol } //${ window . location . host } /` ;
22
+ }
23
+
24
+ const baseUrl = getBaseUrl ( ) ;
25
+
26
+ // Use relative paths in the mappings
6
27
const urlMappings = {
7
- "openshift-acs" : "https://docs.openshift.com/ acs/" ,
8
- "openshift-builds" : "https://docs.openshift.com/ builds/" ,
9
- "openshift-enterprise" : "https://docs.openshift.com/ container-platform/" ,
10
- "openshift-gitops" : "https://docs.openshift.com/ gitops/" ,
11
- "openshift-lightspeed" : "https://docs.openshift.com/ lightspeed/" ,
12
- "openshift-origin" : "https://docs.okd.io/ " ,
13
- "openshift-pipelines" : "https://docs.openshift.com/ pipelines/" ,
14
- "openshift-serverless" : "https://docs.openshift.com/ serverless/" ,
15
- "openshift-telco" : "https://docs.openshift.com/ container-platform-telco/" ,
16
- "openshift-logging" : "https://docs.openshift.com/ logging/" ,
28
+ "openshift-acs" : "acs/" ,
29
+ "openshift-builds" : "builds/" ,
30
+ "openshift-enterprise" : "container-platform/" ,
31
+ "openshift-gitops" : "gitops/" ,
32
+ "openshift-lightspeed" : "lightspeed/" ,
33
+ "openshift-origin" : "" ,
34
+ "openshift-pipelines" : "pipelines/" ,
35
+ "openshift-serverless" : "serverless/" ,
36
+ "openshift-telco" : "container-platform-telco/" ,
37
+ "openshift-logging" : "logging/" ,
17
38
} ;
18
39
19
40
function versionSelector ( list ) {
@@ -27,11 +48,13 @@ function versionSelector(list) {
27
48
currentVersion = window . location . pathname . split ( "/" ) [ 2 ] ;
28
49
}
29
50
30
- let baseUrl = urlMappings [ dk ] ;
51
+ // Get the correct URL path from the urlMappings and prepend the base URL
52
+ let productPath = urlMappings [ dk ] ;
53
+ let fullBaseUrl = baseUrl + productPath ;
31
54
32
55
//Handle special OCP case
33
56
if ( [ "3.0" , "3.1" , "3.2" ] . includes ( newVersion ) && dk === "openshift-enterprise" ) {
34
- baseUrl = "https://docs.openshift.com/ enterprise/";
57
+ fullBaseUrl = baseUrl + " enterprise/";
35
58
}
36
59
37
60
if ( ( dk === "openshift-enterprise" || dk === "openshift-origin" ) && currentVersion . charAt ( 0 ) !== newVersion . charAt ( 0 ) ) {
@@ -41,7 +64,7 @@ function versionSelector(list) {
41
64
fileRequested = window . location . pathname . substring ( versionIndex ) ;
42
65
}
43
66
44
- newLink = `${ baseUrl } ${ newVersion } ${ fileRequested } ` ;
67
+ newLink = `${ fullBaseUrl } ${ newVersion } ${ fileRequested } ` ;
45
68
46
69
// without doing async loads, there is no way to know if the path actually
47
70
// exists - so we will just have to load
@@ -253,4 +276,4 @@ function addReferrer() {
253
276
}
254
277
255
278
256
- }
279
+ }
0 commit comments