|
| 1 | +let newLink = ""; |
| 2 | +let newVersion = ""; |
| 3 | +let currentVersion = ""; |
| 4 | +let fileRequested = ""; |
| 5 | + |
| 6 | +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 | +}; |
| 17 | + |
1 | 18 | function versionSelector(list) {
|
| 19 | + "use strict"; |
2 | 20 |
|
3 |
| - // the version we want |
4 | 21 | newVersion = list[list.selectedIndex].value;
|
5 | 22 |
|
6 |
| - // the new final link to load |
7 |
| - newLink = ""; |
8 |
| - |
9 |
| - // the fileRequested |
10 |
| - var fileRequested = ""; |
11 |
| - |
12 |
| - // spilt the current path |
13 |
| - var pathArray = window.location.pathname.split( '/' ); |
14 |
| - |
15 |
| - // so we can get the current version |
16 |
| - currentVersion = pathArray[2]; |
17 |
| - |
18 |
| - // if switching major versions, just take the user to the main landing page |
19 |
| - // as files change a lot between major versions. |
20 |
| - |
21 |
| - if(currentVersion.charAt(0) === newVersion.charAt(0)) { |
22 |
| - // the file path is just the version number + the end of the path |
23 |
| - fileRequested = |
24 |
| - window.location.pathname.substring( |
25 |
| - window.location.pathname.lastIndexOf(currentVersion) + |
26 |
| - currentVersion.length); |
| 23 | + if (dk === "openshift-origin") { |
| 24 | + currentVersion = window.location.pathname.split("/")[1]; |
27 | 25 | } else {
|
28 |
| - fileRequested = "/welcome/index.html"; |
| 26 | + currentVersion = window.location.pathname.split("/")[2]; |
29 | 27 | }
|
30 | 28 |
|
| 29 | + let baseUrl = urlMappings[dk]; |
31 | 30 |
|
32 |
| - // alert(fileRequested); |
| 31 | + //Handle special OCP case |
| 32 | + if (["3.0", "3.1", "3.2"].includes(newVersion) && dk === "openshift-enterprise") { |
| 33 | + baseUrl = "https://docs.openshift.com/enterprise/"; |
| 34 | + } |
33 | 35 |
|
34 |
| - // in 3.3 and above, we changed to container-platform |
35 |
| - if(newVersion == '3.0' || newVersion == '3.1' || newVersion == '3.2') { |
36 |
| - newLink = "https://docs.openshift.com/enterprise/" + |
37 |
| - newVersion + |
38 |
| - fileRequested; |
| 36 | + if ((dk === "openshift-enterprise" || dk === "openshift-origin") && currentVersion.charAt(0) !== newVersion.charAt(0)){ |
| 37 | + fileRequested = "/welcome/index.html"; |
39 | 38 | } else {
|
40 |
| - newLink = "https://docs.openshift.com/container-platform/" + |
41 |
| - newVersion + |
42 |
| - fileRequested; |
| 39 | + const versionIndex = window.location.pathname.lastIndexOf(currentVersion) + currentVersion.length; |
| 40 | + fileRequested = window.location.pathname.substring(versionIndex); |
43 | 41 | }
|
44 | 42 |
|
| 43 | + newLink = `${baseUrl}${newVersion}${fileRequested}`; |
| 44 | + |
45 | 45 | // without doing async loads, there is no way to know if the path actually
|
46 | 46 | // exists - so we will just have to load
|
47 |
| - window.location = newLink; |
| 47 | + // window.location = newLink; |
| 48 | + // testing async validations |
| 49 | + $.ajax({ |
| 50 | + type: 'HEAD', |
| 51 | + url: newLink, |
| 52 | + success: function() { |
| 53 | + window.location.href = newLink; |
| 54 | + }, |
| 55 | + error: function(jqXHR, exception) { |
| 56 | + if(jqXHR.status == 404) { |
| 57 | + list.value = currentVersion; |
| 58 | + const confirmMessage = `This page doesn't exist in version ${newVersion}. Click OK to search the ${newVersion} docs OR Cancel to stay on this page.`; |
| 59 | + if(confirm(confirmMessage)) { |
| 60 | + let searchUrl; |
| 61 | + if (["3.0", "3.1", "3.2"].includes(newVersion) && dk === "openshift-enterprise") { |
| 62 | + searchUrl = `https://google.com/search?q=site:${baseUrl}${newVersion} ${document.title}`; |
| 63 | + } else { |
| 64 | + searchUrl = `https://google.com/search?q=site:${urlMappings[dk]}${newVersion} ${document.title}`; |
| 65 | + } |
| 66 | + window.location.href = searchUrl; |
| 67 | + } else { |
| 68 | + // do nothing, user doesn't want to search |
| 69 | + } |
| 70 | + } else { |
| 71 | + window.location.href = newLink; // assumption here is that we can follow through with a redirect |
| 72 | + } |
| 73 | + } |
| 74 | + }); |
| 75 | +} |
| 76 | + |
| 77 | +// checks what language was selected and then sends the user to the portal for their localized version |
| 78 | +function selectLang(langList) { |
| 79 | + |
| 80 | + var lang = langList[langList.selectedIndex].value; |
| 81 | + var winPath = window.location.pathname; |
| 82 | + |
| 83 | + console.log("Lang: " + lang); |
| 84 | + console.log("Win Path: " + winPath); |
| 85 | + |
| 86 | + var currentVersion = document.getElementById("version-selector").value; |
| 87 | + console.log("CurrentVersion: " + currentVersion); |
| 88 | + |
| 89 | + // path for the file to reference on portal (the last bit removes .html) |
| 90 | + var path = winPath.substring(winPath.lastIndexOf(currentVersion) + (currentVersion.length + 1), winPath.length - 5); |
| 91 | + |
| 92 | + var parts = path.split("/"); |
| 93 | + |
| 94 | + console.log(parts); |
| 95 | + |
| 96 | + // 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 |
| 97 | + console.log(parts[parts.length-1]); |
| 98 | + |
| 99 | + var anchorid = parts[parts.length-1]; |
| 100 | + var book = parts[0]; |
| 101 | + |
| 102 | + // add changed book names here |
| 103 | + if(book == "updating") book = "updating_clusters"; |
| 104 | + if(book == "virt") book = "openshift_virtualization"; |
| 105 | + if(book == "post_installation_configuration") book = "post-installation_configuration"; |
| 106 | + |
| 107 | + // var section = parts[1].replace(/\_/g, "-"); // replace underscore with dash |
| 108 | + // var section = subGroup.toLowerCase().replace(" ", "-"); |
| 109 | + // console.log(section); |
| 110 | + // var subsection = parts[2].replace(/\_/g, "-"); |
| 111 | + // console.log(subsection); |
| 112 | + |
| 113 | + // path = book + "/" + section + "#" + subsection; |
| 114 | + path = book + "#" + anchorid; |
| 115 | + |
| 116 | + console.log("Path: " + path); |
| 117 | + |
| 118 | + var portalBaseURL = "https://access.redhat.com/documentation"; |
| 119 | + var finalURL = portalBaseURL + "/" + lang + "/openshift_container_platform/" + currentVersion + "/html-single/" + path; |
| 120 | + |
| 121 | + console.log("Final URL: " + finalURL); |
| 122 | + window.location.href = finalURL; |
48 | 123 |
|
49 | 124 | }
|
50 | 125 |
|
@@ -87,8 +162,8 @@ function selectVersion(currentVersion) {
|
87 | 162 |
|
88 | 163 | // main file to edit is the file path after the version to the html at
|
89 | 164 | // the end.
|
90 |
| - // Example: https://docs.openshift.com/container-platform/4.4/updating/updating-cluster-between-minor.html |
91 |
| - // file path is updating/updating-cluster-between-minor.adoc |
| 165 | + // Example: https://docs.openshift.com/container-platform/4.4/updating/updating-cluster-within-minor.html |
| 166 | + // file path is updating/updating-cluster-within-minor.adoc |
92 | 167 |
|
93 | 168 | mainFileToEdit =
|
94 | 169 | window.location.pathname.substring(
|
|
0 commit comments