Skip to content

Commit 782f389

Browse files
authored
Merge pull request #93017 from gabriel-rh/standalone-logging-fix-page-loader
fix base URL so it is not hard-coded
2 parents 6b516a0 + fedeb73 commit 782f389

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

_javascripts/page-loader.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@ let newVersion = "";
33
let currentVersion = "";
44
let fileRequested = "";
55

6+
// Get the base URL dynamically
7+
function getBaseUrl() {
8+
9+
// Fallback to current origin
10+
return `${window.location.protocol}//${window.location.host}/`;
11+
}
12+
13+
const baseUrl = getBaseUrl();
14+
15+
// Use relative paths in the mappings
616
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/",
17+
"openshift-acs": "acs/",
18+
"openshift-builds": "builds/",
19+
"openshift-enterprise": "container-platform/",
20+
"openshift-gitops": "gitops/",
21+
"openshift-lightspeed": "lightspeed/",
22+
"openshift-origin": "",
23+
"openshift-pipelines": "pipelines/",
24+
"openshift-serverless": "serverless/",
25+
"openshift-telco": "container-platform-telco/",
26+
"openshift-logging": "logging/",
1727
};
1828

1929
function versionSelector(list) {
@@ -27,11 +37,14 @@ function versionSelector(list) {
2737
currentVersion = window.location.pathname.split("/")[2];
2838
}
2939

30-
let baseUrl = urlMappings[dk];
40+
// Get the correct URL path from the urlMappings and prepend the base URL
41+
let productPath = urlMappings[dk];
42+
let fullBaseUrl = baseUrl + productPath;
43+
3144

3245
//Handle special OCP case
3346
if (["3.0", "3.1", "3.2"].includes(newVersion) && dk === "openshift-enterprise") {
34-
baseUrl = "https://docs.openshift.com/enterprise/";
47+
fullBaseUrl = "https://docs.openshift.com/enterprise/";
3548
}
3649

3750
if ((dk === "openshift-enterprise" || dk === "openshift-origin") && currentVersion.charAt(0) !== newVersion.charAt(0)){
@@ -41,7 +54,7 @@ function versionSelector(list) {
4154
fileRequested = window.location.pathname.substring(versionIndex);
4255
}
4356

44-
newLink = `${baseUrl}${newVersion}${fileRequested}`;
57+
newLink = `${fullBaseUrl}${newVersion}${fileRequested}`;
4558

4659
// without doing async loads, there is no way to know if the path actually
4760
// exists - so we will just have to load

0 commit comments

Comments
 (0)