diff --git a/docs/assets/versions.js b/docs/assets/versions.js index 08bd9e5903..79c961ea53 100644 --- a/docs/assets/versions.js +++ b/docs/assets/versions.js @@ -29,6 +29,25 @@ function getCurrentVersion() { return null; } +/** Same docs page under /en/stable/ (for version warning banner). */ +function getStableDocsUrlForCurrentPage() { + try { + const url = new URL(window.location.href); + const newPath = url.pathname.replace(VERSION_REGEX, '/en/stable/'); + if (newPath === url.pathname) { + return 'https://argo-cd.readthedocs.io/en/stable/'; + } + url.pathname = newPath; + return url.href; + } catch (e) { + return 'https://argo-cd.readthedocs.io/en/stable/'; + } +} + +function escapeHtmlAttr(s) { + return String(s).replace(/&/g, '&').replace(/"/g, '"'); +} + function initializeVersionDropdown() { const callbackName = 'callback_' + new Date().getTime(); window[callbackName] = function(response) { @@ -139,10 +158,11 @@ window.addEventListener("DOMContentLoaded", function() { var headerHeight = document.getElementsByClassName("md-header")[0].offsetHeight; const currentVersion = getCurrentVersion(); if (currentVersion && currentVersion !== "stable") { + const stablePageUrl = escapeHtmlAttr(getStableDocsUrlForCurrentPage()); if (currentVersion === "latest") { - document.querySelector("div[data-md-component=announce]").innerHTML = "
You are viewing the docs for an unreleased version of Argo CD, view the latest stable version.
"; + document.querySelector("div[data-md-component=announce]").innerHTML = "
You are viewing the docs for an unreleased version of Argo CD, view the latest stable version.
"; } else { - document.querySelector("div[data-md-component=announce]").innerHTML = "
You are viewing the docs for a previous version of Argo CD, view the latest stable version.
"; + document.querySelector("div[data-md-component=announce]").innerHTML = "
You are viewing the docs for a previous version of Argo CD, view the latest stable version.
"; } var bannerHeight = document.getElementById('announce-msg').offsetHeight + margin; document.querySelector("header.md-header").style.top = bannerHeight + "px";