Skip to content

Commit 305026f

Browse files
authored
ARROW-18363: [Docs] Include warning when viewing old docs (redirecting to stable/dev docs) (#14839)
This PR is a complementary work to apache/arrow-site#275. It adds a version warning script tag to the `docs/source/_templates/layout.html` and _versionwarnings.js_ file into `docs/source/_static/`. Authored-by: Alenka Frim <[email protected]> Signed-off-by: Joris Van den Bossche <[email protected]>
1 parent 387e95a commit 305026f

2 files changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
(function() {
19+
// adapted 2022-11 from https://mne.tools/versionwarning.js
20+
if (location.hostname == 'arrow.apache.org') {
21+
$.getJSON("https://arrow.apache.org/docs/_static/versions.json", function(data){
22+
var latestStable = data[1].name.replace(" (stable)","");
23+
// HTML tags
24+
var pre = '<div class="container-fluid alert-danger devbar"><div class="row no-gutters"><div class="col-12 text-center">';
25+
var post = '</div></div></div>';
26+
var anchor = 'class="btn btn-danger font-weight-bold ml-3 my-3 align-baseline"';
27+
// Switch button message
28+
var switch_dev = `Switch to unstable development release version`;
29+
var switch_stable = `latest stable release (version ${latestStable})`;
30+
// Path of the page
31+
var location_array = location.pathname.split('/');
32+
var versionPath = location_array[2];
33+
var subPath = location_array[3];
34+
var filePath = location_array.slice(3).join('/');
35+
// Links to stable or dev versions
36+
var uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
37+
var uri_stable = `https://arrow.apache.org/docs/${filePath}`;
38+
39+
if (versionPath == 'developers') {
40+
// developers section in the stable version
41+
filePath = location_array.slice(2).join('/');
42+
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
43+
$.ajax({
44+
type: 'HEAD',
45+
url: `${uri_dev}`,
46+
error: function() {
47+
filePath = '';
48+
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
49+
},
50+
complete: function() {
51+
var showWarning = `${pre}This is documentation for the stable version ` +
52+
`of Apache Arrow (version ${latestStable}). For latest development practices: ` +
53+
`<a ${anchor} href=${uri_dev}>${switch_dev}</a>${post}`
54+
$('.container-fluid').prepend(`${showWarning}`)
55+
}
56+
});
57+
} else if (versionPath.match(/^\d/) < "4") {
58+
// old versions 1.0,. 2.0 or 3.0
59+
$.ajax({
60+
type: 'HEAD',
61+
url: `${uri_stable}`,
62+
error: function() {
63+
filePath = '';
64+
uri_stable = `https://arrow.apache.org/docs/${filePath}`;
65+
},
66+
complete: function() {
67+
$.ajax({
68+
type: 'HEAD',
69+
url: `${uri_dev}`,
70+
error: function() {
71+
filePath = '';
72+
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
73+
},
74+
complete: function() {
75+
pre = '<p style="padding: 1em;font-size: 1em;border: 1px solid red;background: pink;">';
76+
post = '</p>';
77+
anchor = 'class="btn btn-danger" style="font-weight: bold; vertical-align: baseline;' +
78+
'margin: 0.5rem; border-style: solid; border-color: white;"';
79+
var showWarning = `${pre}This is documentation for an old release of ` +
80+
`Apache Arrow (version ${versionPath}). Try the` +
81+
`<a ${anchor} href=${uri_stable}>${switch_stable}</a> or` +
82+
`<a ${anchor} href=${uri_dev}>development (unstable) version. </a>${post}`
83+
$('.document').prepend(`${showWarning}`)
84+
}
85+
});
86+
}
87+
});
88+
} else if (versionPath.match(/^\d/) && subPath == 'developers') {
89+
// older versions of developers section (with numbered version in the URL)
90+
$.ajax({
91+
type: 'HEAD',
92+
url: `${uri_dev}`,
93+
error: function() {
94+
filePath = '';
95+
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
96+
},
97+
complete: function() {
98+
var showWarning = `${pre}This is documentation for an old release of Apache Arrow ` +
99+
`(version ${versionPath}). For latest development practices: ` +
100+
`<a ${anchor} href=${uri_dev}>${switch_dev} </a>${post}`
101+
$('.container-fluid').prepend(`${showWarning}`)
102+
}
103+
});
104+
} else if (versionPath.match(/^\d/)) {
105+
// older versions (with numbered version in the URL)
106+
$.ajax({
107+
type: 'HEAD',
108+
url: `${uri_stable}`,
109+
error: function() {
110+
filePath = '';
111+
uri_stable = `https://arrow.apache.org/docs/${filePath}`;
112+
},
113+
complete: function() {
114+
$.ajax({
115+
type: 'HEAD',
116+
url: `${uri_dev}`,
117+
error: function() {
118+
filePath = '';
119+
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
120+
},
121+
complete: function() {
122+
var showWarning = `${pre}This is documentation for an old release of ` +
123+
`Apache Arrow (version ${versionPath}). Try the` +
124+
`<a ${anchor} href=${uri_stable}>${switch_stable}</a> or` +
125+
`<a ${anchor} href=${uri_dev}>development (unstable) version. </a>${post}`
126+
$('.container-fluid').prepend(`${showWarning}`)
127+
}
128+
});
129+
}
130+
});
131+
}
132+
});
133+
}
134+
})()

‎docs/source/_templates/layout.html‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@
2626
{# Silence the navbar #}
2727
{% block docs_navbar %}
2828
{% endblock %}
29+
30+
{# Add version warnings #}
31+
{% block footer %}
32+
{{ super() }}
33+
<script type="text/javascript" src="/docs/_static/versionwarning.js"></script>
34+
{% endblock %}

0 commit comments

Comments
 (0)