From b2d661e174bb70b6d0cf5cac37d26029fecc2838 Mon Sep 17 00:00:00 2001 From: silverweed Date: Tue, 8 Sep 2026 11:46:58 +0200 Subject: [PATCH] Improve latest-stable doc redirection The current mechanism fails if the symlink `latest-stable` is not set up properly on the server. This is error-prone, as it needs to be updated at every stable release, so we now instead rely on the 404.html to redirect us to the latest stable release. This way `latest-stable` may not exist at all and the redirection will still work properly. Note that this changes the location of the LATEST_RELEASE constant (that still needs to be updated at every release) from selectversion.js to versions.js. selectversion.js now needs versions.js to be included in order to work (this change is done in the root repository). --- 404.md | 8 ++++++++ doc/selectversion.js | 19 ++++--------------- doc/versions.js | 9 +++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 doc/versions.js diff --git a/404.md b/404.md index 0efe952b..05d15459 100644 --- a/404.md +++ b/404.md @@ -2,6 +2,14 @@ layout: empty permalink: /404.html --- + + + diff --git a/doc/selectversion.js b/doc/selectversion.js index 5a09070b..a7b478fe 100644 --- a/doc/selectversion.js +++ b/doc/selectversion.js @@ -1,7 +1,11 @@ /// (c) Axel Naumann, CERN; 2020-03-02 +/// Later updated by giacomo.parolini@cern.ch. +/// IMPORTANT NOTE: this script needs `versions.js` to also be included in order to work! 'use strict'; /// Configurable section. +/// Note that some configuration is in versions.js (notably, the latest release number). It is separate because it +/// also needs to be included in 404.html. // What the master is called. Leave untouched if master has no doc. const master = 'master'; @@ -28,23 +32,8 @@ function url2version(patharr) { ///============================================================================= -// The latest release. NOT necessarily equal to latest-stable, as stable releases are only -// once every two versions. -// >>> CHANGE THIS WHEN A NEW VERSION IS RELEASED! (stable or not) <<< -const LATEST_VERSION = 640; -const LATEST_VERSION_IS_STABLE = LATEST_VERSION % 4 === 0; -const LATEST_STABLE = LATEST_VERSION - 2 * !LATEST_VERSION_IS_STABLE; -const FIRST_VERSION = 610; - // Redirect from latest-stable to the actual latest release let patharr = window.location.pathname.replace(/\/+/g, '/').split('/'); -if (url2version(patharr) === 'latest-stable') { - patharr[patharr.length - urlrootdirs] = `v${LATEST_STABLE}`; - let newLocation = patharr.join('/'); - if (window.location.hash) - newLocation += `#${window.location.hash}`; - window.location.replace(newLocation); -} let versions = ["master", "latest-stable"]; for (let i = LATEST_VERSION; i >= FIRST_VERSION; i -= 2) { diff --git a/doc/versions.js b/doc/versions.js new file mode 100644 index 00000000..07ba6cfb --- /dev/null +++ b/doc/versions.js @@ -0,0 +1,9 @@ +'use strict'; + +// The latest release. NOT necessarily equal to latest-stable, as stable releases are only +// once every two versions. +// >>> CHANGE THIS WHEN A NEW VERSION IS RELEASED! (stable or not) <<< +const LATEST_VERSION = 640; +const LATEST_VERSION_IS_STABLE = LATEST_VERSION % 4 === 0; +const LATEST_STABLE = LATEST_VERSION - 2 * !LATEST_VERSION_IS_STABLE; +const FIRST_VERSION = 610;