update warnOldDocs.js and symlink for release

This will also git commit before and after the upload of the docs, so as
to make sure that changes to warnOldDocs.js are recoverable.
This commit is contained in:
Roland Kuhn 2016-03-08 15:11:43 +01:00
parent e89b5e3a58
commit 0acf03f528
2 changed files with 121 additions and 70 deletions

View file

@ -3,28 +3,67 @@ jQuery(document).ready(function ($) {
});
function initOldVersionWarnings($) {
$.get(versionsJsonUri(), function (akkaVersionsData) {
var thisVersion = browsedAkkaVersion();
if (thisVersion.includes("-SNAPSHOT")) {
$.get("//akka.io/versions.json", function (akkaVersionsData) {
var site = splitPath();
console.log(site);
if (site.v === 'snapshot') {
console.log("Detected SNAPSHOT Akka version...");
// we could show a 'hey, this is a snapshot' notice
showSnapshotWarning(site);
} else {
for (var series in akkaVersionsData) {
if (thisVersion.startsWith(series)) {
showVersionWarning(thisVersion, akkaVersionsData, akkaVersionsData[series]);
for (var series in akkaVersionsData[site.p]) {
if (site.v.startsWith(series)) {
return showVersionWarning(site, akkaVersionsData, series);
}
}
}
});
}
function insteadUrl(version, instead) {
return ("" + window.location).replace(version, instead);
function splitPath() {
var path = window.location.pathname;
path = path.substring(path.indexOf("akka")); // string off leading /docs/
var base = '' + window.location;
base = base.substring(0, base.indexOf(path));
var projectEnd = path.indexOf("/");
var versionEnd = path.indexOf("/", projectEnd + 1);
var project = path.substring(0, projectEnd);
var version = path.substring(projectEnd + 1, versionEnd);
var rest = path.substring(versionEnd + 1);
return {"b":base, "p":project, "v":version, "r":rest};
}
function showVersionWarning(version, akkaVersionsData, seriesInfo) {
console.log("Akka version:", version);
var targetUrl = ("" + window.location).replace(version, seriesInfo.latest);
function getInstead(akkaVersionsData, project, instead) {
if (Array.isArray(instead)) {
var found = akkaVersionsData[instead[0]][instead[1]];
var proj = instead[0];
} else {
var found = akkaVersionsData[project][instead];
var proj = project;
}
return {"latest":found.latest, "project":proj};
}
function targetUrl(samePage, site, instead) {
var page = site.r;
if (samePage !== true) {
if (page.substring(0, 5) == 'scala') {
page = 'scala.html';
} else if (page.substring(0, 4) == 'java') {
page = 'java.html';
} else {
page = 'index.html';
}
}
var project = instead.project;
if (!project) {
project = site.p;
}
return site.b + project + '/' + instead.latest + '/' + page;
}
function showVersionWarning(site, akkaVersionsData, series) {
var version = site.v;
var seriesInfo = akkaVersionsData[site.p][series];
var $floatyWarning = $('<div id="floaty-warning"/>');
console.log("Current version info", seriesInfo);
@ -36,17 +75,25 @@ function showVersionWarning(version, akkaVersionsData, seriesInfo) {
if (isOutdated) {
needsToShow = true;
$floatyWarning.addClass("warning");
var instead = akkaVersionsData[seriesInfo.instead].latest;
console.log("Akka " + version + " is outdated. Suggesting 'latest' of ", seriesInfo.instead, "by 'instead' key.");
var instead = getInstead(akkaVersionsData, site.p, seriesInfo.instead);
var insteadSeries = targetUrl(false, site, instead);
var insteadPage = targetUrl(true, site, instead);
$floatyWarning
.append(
'<p>' +
'<span style="font-weight: bold">This version of Akka (' + version + ') has been end-of-lifed and is currently not supported! </span><br/>' +
'Please upgrade to <a href="' + insteadUrl(version, instead) + '">Akka ' + instead + '</a> or <a href="http://www.lightbend.com/products/lightbend-reactive-platform">Lightbend Reactive Platform</a> as soon as possible.' +
'</p>');
'<p><span style="font-weight: bold">This version of Akka (' + site.p + ' / ' + version + ') is outdated and not supported! </span></p>' +
'<p>Please upgrade to version <a href="' + insteadSeries + '">' + instead.latest + '</a> as soon as possible.</p>' +
'<p id="samePageLink"></p>');
$.ajax({
url: insteadPage,
type: 'HEAD',
success: function() {
$('#samePageLink').html('<a href="' + insteadPage + '">Click here to go to the same page on the ' + instead.latest + ' version of the docs.</a>');
}
});
}
if (!isLatestInSeries) {
needsToShow = true;
$floatyWarning
@ -54,28 +101,18 @@ function showVersionWarning(version, akkaVersionsData, seriesInfo) {
'<p>' +
'You are browsing the docs for Akka ' + version + ', ' +
'however the latest release in this series is: ' +
'<a href="' + targetUrl + '">' + seriesInfo.latest + '</a>. <br/>' +
'<a href="' + targetUrl(true, site, seriesInfo) + '">' + seriesInfo.latest + '</a>. <br/>' +
'</p>');
}
if (isOutdated) {
$floatyWarning
.append(
'<p>' +
'<a href="' + insteadUrl(version, instead) + '">Click here to go to the same page on the ' + akkaVersionsData[seriesInfo.instead].latest + ' version of the docs.</a>' +
'</p>');
} else if (!isLatestInSeries) {
$floatyWarning
.append(
'<p>' +
'<a href="' + targetUrl + '">Click here to go to the same page on the ' + seriesInfo.latest + ' version of the docs.</a>' +
'</p>')
}
if (needsToShow && !outdatedVersionWasAcked(version)) {
var $close = $('<span id="close-floaty-window">Close [X]</span>')
if (needsToShow && !versionWasAcked(site.p, version)) {
var style = '';
if (site.p != 'akka-stream-and-http-experimental') {
style = 'style="color:black"'
}
var $close = $('<button id="close-floaty-window" ' + style + '>Dismiss Warning for a Day</button>')
.click(function () {
ackOutdatedVersionForADay(version);
ackVersionForADay(site.p, version);
$floatyWarning.hide();
});
@ -84,48 +121,62 @@ function showVersionWarning(version, akkaVersionsData, seriesInfo) {
.append($close)
.prependTo("body")
.show()
.delay(10 * 1000)
.fadeOut();
}
}
// e.g. "docs/akka/2.3.10/scala/persistence.html" => "2.3.10"
function browsedAkkaVersion() {
var globalSetting = window.DOCUMENTATION_OPTIONS.VERSION; // generated by Sphinx
if (globalSetting) {
return globalSetting;
} else {
var path = window.location.pathname;
var path2 = path.substring(path.indexOf("/", "/docs/akka".length) + 1);
var version = path2.substring(0, path2.indexOf("/"));
console.log("Detected version of docs using window.location parsing:", version);
return version;
}
}
function showSnapshotWarning(site) {
if (!versionWasAcked(site.p, 'snapshot')) {
var $floatyWarning = $('<div id="floaty-warning" class="warning"/>');
var instead = { 'latest' : 'current' };
var insteadSeries = targetUrl(false, site, instead);
var insteadPage = targetUrl(true, site, instead);
function versionsJsonUri() {
if (window.location.pathname.includes("stream-and-http"))
return "http://doc.akka.io/docs/akka-stream-and-http-experimental/versions.json";
else
return "http://doc.akka.io/docs/akka/versions.json";
$floatyWarning
.append(
'<p><span style="font-weight: bold">You are browsing the snapshot documentation, which most likely does not correspond to the artifacts you are using! </span></p>' +
'<p>We recommend that you head over to <a href="' + insteadSeries + '">the latest stable version</a> instead.</p>' +
'<p id="samePageLink"></p>');
$.ajax({
url: insteadPage,
type: 'HEAD',
success: function() {
$('#samePageLink').html('<a href="' + insteadPage + '">Click here to go to the same page on the latest stable version of the docs.</a>');
}
});
var style = '';
if (site.p != 'akka-stream-and-http-experimental') {
style = 'style="color:black"'
}
var $close = $('<button id="close-floaty-window" ' + style + '>Dismiss Warning for a Day</button>')
.click(function () {
ackVersionForADay(site.p, 'snapshot');
$floatyWarning.hide();
});
$floatyWarning
.hide()
.append($close)
.prependTo("body")
.show()
}
}
// --- ack outdated versions ---
function ackOutdatedVersionCookieName(version) {
return "ack-outdated-" + version;
function ackVersionCookieName(project, version) {
return "ack-" + project + "-" + version;
}
function ackOutdatedVersionForADay(version) {
function ackVersionForADay(project, version) {
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
setCookie(ackOutdatedVersionCookieName(version), 'true', 1)
setCookie(ackVersionCookieName(project, version), 'true', 1)
}
function outdatedVersionWasAcked(version) {
function versionWasAcked(project, version) {
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
@ -137,5 +188,5 @@ function outdatedVersionWasAcked(version) {
return "";
}
return getCookie(ackOutdatedVersionCookieName(version)) === 'true';
return getCookie(ackVersionCookieName(project, version)) === 'true';
}

View file

@ -360,17 +360,17 @@ if [ $dry_run ]; then
echodry " rsync -rlpvz --chmod=Dg+ws,Fg+w --exclude ${release_dir}/downloads ${release_dir}/ ${publish_path}/"
echodry " sbt uploadRelease"
else
important ssh ${release_server} "cd ${release_path}/docs/akka; git add .; git commit -m 'before publishing version $version'; true"
important rsync -rlpvz --chmod=Dg+ws,Fg+w --exclude ${release_dir}/downloads ${release_dir}/ ${publish_path}/
important sbt uploadRelease
important ssh ${release_server} cp -v ${release_path}/docs/akka/${version}/_static/warnOldDocs.js ${release_path}/docs/akka
important ssh ${release_server} ln -snvf ../../warnOldDocs.js ${release_path}/docs/akka/${version}/_static/warnOldDocs.js
important ssh ${release_server} "cd ${release_path}/docs/akka; git add .; git commit -m 'publish version $version'"
fi
echolog "Updating http://doc.akka.io/docs/versions.json [from $script_dir/../../akka-docs/versions.json]..."
if [ $dry_run ]; then
echodry "Not actually updating versions.json. Command:"
echodry " important scp $script_dir/../../akka-docs/versions.json ${publish_path}/docs/"
else
important scp $script_dir/../../akka-docs/versions.json ${publish_path}/docs/
fi
echolog "*****"
echolog "Do not forget to update versions.json on akka.github.com!"
echolog "*****"
if [ $dry_run ]; then
if [ $no_revert ]; then