docs: Add warning to version-specific docunmentation pages (#2248)

See details on issue #2214
Basically, we want to make users more aware they are looking at old version of the docs.
This commit is contained in:
Luan Nico
2023-01-02 17:58:01 -05:00
committed by GitHub
parent 6c5ef0540a
commit 55bb0afd7a
3 changed files with 40 additions and 1 deletions

View File

@ -33,9 +33,22 @@ function convertVersionsToHtmlLinks(versionsList, currentVersion) {
return out;
}
function maybeAddWarning(versions, currentVersion) {
const specialVersions = ['main', 'local'];
const latestVersion = versions.filter(e => !specialVersions.includes(e))[0];
const nonWarningVersions = [...specialVersions, latestVersion];
const showWarning = !nonWarningVersions.includes(currentVersion);
if (showWarning) {
$('#version-warning')
.find('.version').text(currentVersion).end()
.removeClass('hidden');
}
}
function buildVersionsMenu(data) {
const versions = data.split('\n');
const currentVersion = getCurrentDocVersion();
const versionButtons = convertVersionsToHtmlLinks(data.split('\n'), currentVersion);
const versionButtons = convertVersionsToHtmlLinks(versions, currentVersion);
$('div.versions-placeholder').append(`
<div id="versions-menu" tabindex="-1">
<div class="btn">
@ -54,6 +67,8 @@ function buildVersionsMenu(data) {
// A timeout ensures that `click` can propagate to child <A/> elements.
setTimeout(() => $(this).removeClass("active"), 200);
});
maybeAddWarning(versions, currentVersion);
}
// Start loading the versions list as soon as possible, don't wait for DOM