From 0acf03f5285844f683bcafb6f31b19e790798ca5 Mon Sep 17 00:00:00 2001 From: Roland Kuhn Date: Tue, 8 Mar 2016 15:11:43 +0100 Subject: [PATCH] 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. --- .../_sphinx/themes/akka/static/warnOldDocs.js | 177 +++++++++++------- project/scripts/release | 14 +- 2 files changed, 121 insertions(+), 70 deletions(-) diff --git a/akka-docs/_sphinx/themes/akka/static/warnOldDocs.js b/akka-docs/_sphinx/themes/akka/static/warnOldDocs.js index fb5af34106..7474ee3adf 100644 --- a/akka-docs/_sphinx/themes/akka/static/warnOldDocs.js +++ b/akka-docs/_sphinx/themes/akka/static/warnOldDocs.js @@ -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 = $('
'); 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( - '

' + - 'This version of Akka (' + version + ') has been end-of-lifed and is currently not supported!
' + - 'Please upgrade to Akka ' + instead + ' or Lightbend Reactive Platform as soon as possible.' + - '

'); + '

This version of Akka (' + site.p + ' / ' + version + ') is outdated and not supported!

' + + '

Please upgrade to version ' + instead.latest + ' as soon as possible.

' + + ''); + $.ajax({ + url: insteadPage, + type: 'HEAD', + success: function() { + $('#samePageLink').html('Click here to go to the same page on the ' + instead.latest + ' version of the docs.'); + } + }); } - + if (!isLatestInSeries) { needsToShow = true; $floatyWarning @@ -54,28 +101,18 @@ function showVersionWarning(version, akkaVersionsData, seriesInfo) { '

' + 'You are browsing the docs for Akka ' + version + ', ' + 'however the latest release in this series is: ' + - '' + seriesInfo.latest + '.
' + + '' + seriesInfo.latest + '.
' + '

'); } - if (isOutdated) { - $floatyWarning - .append( - '

' + - 'Click here to go to the same page on the ' + akkaVersionsData[seriesInfo.instead].latest + ' version of the docs.' + - '

'); - } else if (!isLatestInSeries) { - $floatyWarning - .append( - '

' + - 'Click here to go to the same page on the ' + seriesInfo.latest + ' version of the docs.' + - '

') - } - - if (needsToShow && !outdatedVersionWasAcked(version)) { - var $close = $('Close [X]') + if (needsToShow && !versionWasAcked(site.p, version)) { + var style = ''; + if (site.p != 'akka-stream-and-http-experimental') { + style = 'style="color:black"' + } + var $close = $('') .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 = $('
'); + + 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( + '

You are browsing the snapshot documentation, which most likely does not correspond to the artifacts you are using!

' + + '

We recommend that you head over to the latest stable version instead.

' + + ''); + $.ajax({ + url: insteadPage, + type: 'HEAD', + success: function() { + $('#samePageLink').html('Click here to go to the same page on the latest stable version of the docs.'); + } + }); + var style = ''; + if (site.p != 'akka-stream-and-http-experimental') { + style = 'style="color:black"' + } + var $close = $('') + .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'; } diff --git a/project/scripts/release b/project/scripts/release index d3abb58d7a..41067f8ddb 100755 --- a/project/scripts/release +++ b/project/scripts/release @@ -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