Skip to content

Instantly share code, notes, and snippets.

@AlenkaF
Last active December 1, 2022 11:18
Show Gist options
  • Save AlenkaF/1f3e734b1ff2c5fa2b4ae808345aaa94 to your computer and use it in GitHub Desktop.
Save AlenkaF/1f3e734b1ff2c5fa2b4ae808345aaa94 to your computer and use it in GitHub Desktop.
(function() {
// adapted 2022-11 from https://mne.tools/versionwarning.js
if (location.hostname == '') {
var latestStable = '10.0.0';
// HTML tags
var pre = '<div class="container-fluid alert-danger devbar"><div class="row no-gutters"><div class="col-12 text-center">';
var post = '</div></div></div>';
var anchor = 'class="btn btn-danger font-weight-bold ml-3 my-3 align-baseline"';
// Switch button message
var switch_dev = `Switch to unstable development release version`;
var switch_stable = `latest stable release (version ${latestStable})`;
// Path of the page
var location_array = location.pathname.split('/');
var versionPath = location_array[6];
var subPath = location_array[7];
var filePath = location_array.slice(7).join('/');
// Links to stable or dev versions
var uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
var uri_stable = `https://arrow.apache.org/docs/${filePath}`;
if (versionPath == 'developers') {
// developers section in the stable version
filePath = location_array.slice(6).join('/');
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
$.ajax({
type: 'HEAD',
url: `${uri_dev}`,
error: function() {
filePath = '';
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
},
complete: function() {
var showWarning = `${pre}This is documentation for the stable version ` +
`of Apache Arrow (version ${latestStable}). For latest development practices: ` +
`<a ${anchor} href=${uri_dev}>${switch_dev}</a>${post}`
$('.container-fluid').prepend(`${showWarning}`)
}
});
} else if (versionPath.match(/^\d/) < "4") {
// old versions 1.0,. 2.0 or 3.0
$.ajax({
type: 'HEAD',
url: `${uri_stable}`,
error: function() {
filePath = '';
uri_stable = `https://arrow.apache.org/docs/${filePath}`;
},
complete: function() {
$.ajax({
type: 'HEAD',
url: `${uri_dev}`,
error: function() {
filePath = '';
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
},
complete: function() {
pre = '<p style="padding: 1em;font-size: 1em;border: 1px solid red;background: pink;">';
post = '</p>';
anchor = 'class="btn btn-danger" style="font-weight: bold; vertical-align: baseline;' +
'margin: 0.5rem; border-style: solid; border-color: white;"';
var showWarning = `${pre}This is documentation for an old release of ` +
`Apache Arrow (version ${versionPath}). Try the` +
`<a ${anchor} href=${uri_stable}>${switch_stable}</a> or` +
`<a ${anchor} href=${uri_dev}>development (unstable) version. </a>${post}`
$('.document').prepend(`${showWarning}`)
}
});
}
});
} else if (versionPath.match(/^\d/) && subPath == 'developers') {
// older versions of developers section (with numbered version in the URL)
$.ajax({
type: 'HEAD',
url: `${uri_dev}`,
error: function() {
filePath = '';
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
},
complete: function() {
var showWarning = `${pre}This is documentation for an old release of Apache Arrow ` +
`(version ${versionPath}). For latest development practices: ` +
`<a ${anchor} href=${uri_dev}>${switch_dev} </a>${post}`
$('.container-fluid').prepend(`${showWarning}`)
}
});
} else if (versionPath.match(/^\d/)) {
// older versions (with numbered version in the URL)
$.ajax({
type: 'HEAD',
url: `${uri_stable}`,
error: function() {
filePath = '';
uri_stable = `https://arrow.apache.org/docs/${filePath}`;
},
complete: function() {
$.ajax({
type: 'HEAD',
url: `${uri_dev}`,
error: function() {
filePath = '';
uri_dev = `https://arrow.apache.org/docs/dev/${filePath}`;
},
complete: function() {
var showWarning = `${pre}This is documentation for an old release of ` +
`Apache Arrow (version ${versionPath}). Try the` +
`<a ${anchor} href=${uri_stable}>${switch_stable}</a> or` +
`<a ${anchor} href=${uri_dev}>development (unstable) version. </a>${post}`
$('.container-fluid').prepend(`${showWarning}`)
}
});
}
});
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment