Skip to content

Commit c8841dd

Browse files
Merge pull request #90201 from openshift-cherrypick-robot/cherry-pick-90185-to-rhacs-docs-4.7
[rhacs-docs-4.7] Copied updated resource files for preview build from main
2 parents 0b85908 + 49dbc3f commit c8841dd

File tree

3 files changed

+500
-149
lines changed

3 files changed

+500
-149
lines changed

_javascripts/page-loader.js

Lines changed: 110 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,125 @@
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+
118
function versionSelector(list) {
19+
"use strict";
220

3-
// the version we want
421
newVersion = list[list.selectedIndex].value;
522

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];
2725
} else {
28-
fileRequested = "/welcome/index.html";
26+
currentVersion = window.location.pathname.split("/")[2];
2927
}
3028

29+
let baseUrl = urlMappings[dk];
3130

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+
}
3335

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";
3938
} 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);
4341
}
4442

43+
newLink = `${baseUrl}${newVersion}${fileRequested}`;
44+
4545
// without doing async loads, there is no way to know if the path actually
4646
// 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;
48123

49124
}
50125

@@ -87,8 +162,8 @@ function selectVersion(currentVersion) {
87162

88163
// main file to edit is the file path after the version to the html at
89164
// 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
92167

93168
mainFileToEdit =
94169
window.location.pathname.substring(

_stylesheets/docs.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ nav#main {
3636
margin-left: 20px;
3737
}
3838

39+
/* Styling for new page/section edit buttons */
40+
.edit-page-button {
41+
z-index: 1;
42+
/* Absolutely aligns element with next "relative" parent */
43+
position: absolute;
44+
top: 15px;
45+
/* 25px to match parent padding */
46+
right: 25px;
47+
}
48+
.edit-section-button {
49+
z-index: 1;
50+
float: right;
51+
position: relative;
52+
top: 5px;
53+
right: 10px;
54+
}
55+
3956
/* Tweaks for the Google-generated search widget */
4057
.cse .gsc-control-cse, .gsc-control-cse, table.gsc-search-box td.gsc-input {
4158
padding: 0;
@@ -53,6 +70,21 @@ div.gsc-option-menu-container>div.gsc-selected-option-container {
5370
margin: 0 10px;
5471
}
5572

73+
/* target safari only hack: https://stackoverflow.com/a/25975282/6758654 */
74+
/* Addresses https://github.com/openshift/openshift-docs/issues/40909 */
75+
@media not all and (min-resolution:.001dpcm) { @supports (-webkit-appearance:none) and (stroke-color:transparent) {
76+
#hc-search.wide {
77+
z-index: 50;
78+
margin-top: 28px;
79+
margin-left: -15px;
80+
}
81+
82+
.sidebar.wide {
83+
padding-top: 30px;
84+
}
85+
}}
86+
/* end safari only */
87+
5688
/* ------------------------------------------------------------
5789
Image: "Spin" https://www.flickr.com/photos/eflon/3655695161/
5890
Author: eflon https://www.flickr.com/photos/eflon/
@@ -339,6 +371,7 @@ h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
339371
position: relative;
340372
text-transform: none;
341373
overflow-wrap: break-word;
374+
padding-right: 35px !important;
342375
}
343376

344377
h2>a.anchor, h3>a.anchor, h4>a.anchor, h5>a.anchor, h6>a.anchor {
@@ -532,6 +565,7 @@ h2:hover>a.anchor, h2>a.anchor:hover, h3:hover>a.anchor, h3>a.anchor:hover, h4:h
532565
}
533566

534567
#toc {
568+
user-select: none;
535569
float: right;
536570
padding-top: 0.1em !important;
537571
font-size: 0.8em;
@@ -2123,6 +2157,7 @@ ol.lowergreek {
21232157
border: 0;
21242158
background: none;
21252159
margin-bottom: 0;
2160+
word-break: break-word;
21262161
}
21272162

21282163
.hdlist>table>tbody>tr, .colist>table>tbody>tr {

0 commit comments

Comments
 (0)