Skip to content

Commit 76ba530

Browse files
authored
Merge pull request #92934 from gabriel-rh/local-page-loader
try local pageloader js file for baseurl
2 parents b069318 + 66b835f commit 76ba530

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

_javascripts/page-loader.js

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

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
627
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/",
1738
};
1839

1940
function versionSelector(list) {
@@ -27,11 +48,13 @@ function versionSelector(list) {
2748
currentVersion = window.location.pathname.split("/")[2];
2849
}
2950

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;
3154

3255
//Handle special OCP case
3356
if (["3.0", "3.1", "3.2"].includes(newVersion) && dk === "openshift-enterprise") {
34-
baseUrl = "https://docs.openshift.com/enterprise/";
57+
fullBaseUrl = baseUrl + "enterprise/";
3558
}
3659

3760
if ((dk === "openshift-enterprise" || dk === "openshift-origin") && currentVersion.charAt(0) !== newVersion.charAt(0)){
@@ -41,7 +64,7 @@ function versionSelector(list) {
4164
fileRequested = window.location.pathname.substring(versionIndex);
4265
}
4366

44-
newLink = `${baseUrl}${newVersion}${fileRequested}`;
67+
newLink = `${fullBaseUrl}${newVersion}${fileRequested}`;
4568

4669
// without doing async loads, there is no way to know if the path actually
4770
// exists - so we will just have to load
@@ -253,4 +276,4 @@ function addReferrer() {
253276
}
254277

255278

256-
}
279+
}

_templates/_page_openshift.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@
577577
<script src="https://docs.okd.io/latest/_javascripts/bootstrap-offcanvas.js" type="text/javascript"></script>
578578
<script src="https://docs.okd.io/latest/_javascripts/reformat-html.js" type="text/javascript"></script>
579579
<script src="https://docs.okd.io/latest/_javascripts/hc-search.js" type="text/javascript"></script>
580-
<script src="https://docs.okd.io/latest/_javascripts/page-loader.js" type="text/javascript"></script>
580+
<script src="/logging/6.0/_javascripts/page-loader.js" type="text/javascript"></script>
581581
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" type="text/javascript"></script>
582582
<script src="https://docs.okd.io/latest/_javascripts/clipboard.js" type="text/javascript"></script>
583583
<script src="https://docs.okd.io/latest/_javascripts/collapsible.js" type="text/javascript"></script>

0 commit comments

Comments
 (0)