Skip to content

Commit 858b70e

Browse files
Merge pull request #39656 from vikram-redhat/main
Testing search by title
2 parents 9e66c2c + 5f347f9 commit 858b70e

File tree

1 file changed

+55
-13
lines changed

1 file changed

+55
-13
lines changed

_javascripts/page-loader.js

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
// the new final link to load
2+
newLink = "";
3+
newVersion = "";
4+
currentVersion = "";
5+
6+
// the fileRequested
7+
fileRequested = "";
8+
19
function versionSelector(list) {
210

311
// the version we want
412
newVersion = list[list.selectedIndex].value;
513

6-
// the new final link to load
7-
newLink = "";
8-
9-
// the fileRequested
10-
var fileRequested = "";
11-
1214
// spilt the current path
1315
var pathArray = window.location.pathname.split( '/' );
1416

@@ -28,7 +30,6 @@ function versionSelector(list) {
2830
fileRequested = "/welcome/index.html";
2931
}
3032

31-
3233
// alert(fileRequested);
3334

3435
// in 3.3 and above, we changed to container-platform
@@ -44,7 +45,27 @@ function versionSelector(list) {
4445

4546
// without doing async loads, there is no way to know if the path actually
4647
// exists - so we will just have to load
47-
window.location = newLink;
48+
// window.location = newLink;
49+
// testing async validations
50+
$.ajax({
51+
type: 'HEAD',
52+
url: newLink,
53+
success: function() {
54+
window.location = newLink;
55+
},
56+
error: function(jqXHR, exception) {
57+
if(jqXHR.status == 404) {
58+
list.value = currentVersion;
59+
if(confirm("This page doesn't exist in version " + newVersion + ". Click OK to search the " + newVersion + " docs OR Cancel to stay on this page.")) {
60+
window.location = "https://google.com/search?q=site:https://docs.openshift.com/container-platform/" + newVersion + " " + document.title;
61+
} else {
62+
// do nothing, user doesn't want to search
63+
}
64+
} else {
65+
window.location = newLink; // assumption here is that we can follow through with a redirect
66+
}
67+
}
68+
});
4869

4970
}
5071

@@ -58,20 +79,41 @@ function selectLang(langList) {
5879
console.log("Win Path: " + winPath);
5980

6081
var currentVersion = document.getElementById("version-selector").value;
61-
// var currentVersion = "4.7";
6282
console.log("CurrentVersion: " + currentVersion);
6383

6484
// path for the file to reference on portal (the last bit removes .html)
65-
var path = winPath.substring(winPath.lastIndexOf(currentVersion) + currentVersion.length, winPath.length - 5);
85+
var path = winPath.substring(winPath.lastIndexOf(currentVersion) + (currentVersion.length + 1), winPath.length - 5);
86+
87+
var parts = path.split("/");
88+
89+
console.log(parts);
90+
91+
// map things to html-single. While plain HTML is preferred, it is harder to map and get all anchors right. html-single ensures there is no 404 and the user at least lands on the right book
92+
console.log(parts[parts.length-1]);
93+
94+
var anchorid = parts[parts.length-1];
95+
var book = parts[0];
96+
97+
// add changed book names here
98+
if(book == "updating") book = "updating_clusters";
99+
if(book == "virt") book = "openshift_virtualization";
100+
if(book == "post_installation_configuration") book = "post-installation_configuration";
101+
102+
// var section = parts[1].replace(/\_/g, "-"); // replace underscore with dash
103+
// var section = subGroup.toLowerCase().replace(" ", "-");
104+
// console.log(section);
105+
// var subsection = parts[2].replace(/\_/g, "-");
106+
// console.log(subsection);
107+
108+
// path = book + "/" + section + "#" + subsection;
109+
path = book + "#" + anchorid;
66110

67111
console.log("Path: " + path);
68112

69113
var portalBaseURL = "https://access.redhat.com/documentation";
70-
var finalURL = portalBaseURL + "/" + lang + "/openshift_container_platform/" + currentVersion + "/html/" + path;
114+
var finalURL = portalBaseURL + "/" + lang + "/openshift_container_platform/" + currentVersion + "/html-single/" + path;
71115

72116
console.log("Final URL: " + finalURL);
73-
74-
// alert(finalURL);
75117
window.location.href = finalURL;
76118

77119
}

0 commit comments

Comments
 (0)