Skip to content

Commit 9c81743

Browse files
committed
[doc] Separate latest-stable from latest release in selectversions.js
Now latest-stable will always point to the latest *stable* release, not just the latest release. Latest stable is calculated as (version % 4 == 0), which is true for all releases after 632 (which are the only ones we're concerned with, since the previous are not "latest" anymore :-)
1 parent 9fdc88a commit 9c81743

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

doc/selectversion.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,37 @@ function url2version(patharr) {
2727
}
2828

2929
///=============================================================================
30-
const LATEST_VERSION = 636; // CHANGE THIS WHEN A NEW VERSION IS RELEASED
30+
31+
// The latest release. NOT necessarily equal to latest-stable, as stable releases are only
32+
// once every two versions.
33+
// >>> CHANGE THIS WHEN A NEW VERSION IS RELEASED! (stable or not) <<<
34+
const LATEST_VERSION = 638;
35+
const LATEST_VERSION_IS_STABLE = LATEST_VERSION % 4 === 0;
36+
const LATEST_STABLE = LATEST_VERSION - 2 * !LATEST_VERSION_IS_STABLE;
3137
const FIRST_VERSION = 610;
3238

3339
// Redirect from latest-stable to the actual latest release
3440
let patharr = window.location.pathname.replace(/\/+/g, '/').split('/');
3541
if (url2version(patharr) === 'latest-stable') {
36-
patharr[patharr.length - urlrootdirs] = `v${LATEST_VERSION}`;
42+
patharr[patharr.length - urlrootdirs] = `v${LATEST_STABLE}`;
3743
let newLocation = patharr.join('/');
3844
if (window.location.hash)
3945
newLocation += `#${window.location.hash}`;
4046
window.location.replace(newLocation);
4147
}
4248

43-
const LATEST_STABLE_IDX = 1;
4449
let versions = ["master", "latest-stable"];
4550
for (let i = LATEST_VERSION; i >= FIRST_VERSION; i -= 2) {
4651
versions.push(`v${i}`);
4752
}
4853

54+
// Index of the "latest-stable" element in `versions`. Never changes.
55+
const LATEST_STABLE_IDX = 1;
56+
// Index of the actual version that latest-stable redirects to in `versions`.
57+
// It's either the one immediately after latest-stable or 2 places after it (depending
58+
// whether the latest release is stable or not).
59+
const LATEST_STABLE_REDIRECT_IDX = LATEST_STABLE_IDX + 1 + !LATEST_VERSION_IS_STABLE;
60+
4961
let thisvers = url2version(patharr);
5062
$('.dropbtn').html("Version " + url2label(thisvers));
5163

@@ -59,21 +71,26 @@ for (let i = 0; i < versions.length; ++i) {
5971
a.innerText = url2label(version);
6072
dropdown.append(a);
6173

62-
// latest-stable redirects to the actual latest version
74+
// latest-stable redirects to the actual latest stable version
6375
if (i === LATEST_STABLE_IDX) {
6476
// this gets checked already by the actual latest version, so don't waste
6577
// an AJAX request for it.
6678
latestStableLink = a;
6779
continue;
6880
}
6981

82+
// Enable all links that are reachable by a HEAD request.
7083
let url = `${baseUrl}/${version}/${patharr[patharr.length-1]}`;
7184
let request = new XMLHttpRequest();
7285
request.open('HEAD', url, true);
7386
request.onreadystatechange = () => {
7487
let linksToChange = [a];
75-
if (i === LATEST_STABLE_IDX + 1)
88+
89+
// Normally we only enable the link relative to the HEAD request we just did, but in case this is
90+
// the latest stable version we also enable the "latest-stable" link.
91+
if (i === LATEST_STABLE_REDIRECT_IDX)
7692
linksToChange.push(latestStableLink);
93+
7794
for (let link of linksToChange) {
7895
if (request.readyState === 4 && request.status === 404) {
7996
link.style['color'] = "gray";

0 commit comments

Comments
 (0)