Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: docs js regex fix, cherry-pick pr for release-2.12 (#19351) #19352

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions docs/assets/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const observerCallback = function(mutationsList, observer) {
const observer = new MutationObserver(observerCallback);
observer.observe(targetNode, observerOptions);

function getCurrentVersion() {
const currentVersion = window.location.href.match(/\/en\/(release-(?:v\d+|[\d\.]+|\w+)|latest|stable)\//);
if (currentVersion && currentVersion.length > 1) {
return currentVersion[1];
}
return null;
}

function initializeVersionDropdown() {
const callbackName = 'callback_' + new Date().getTime();
window[callbackName] = function(response) {
Expand All @@ -42,18 +50,18 @@ function initializeVersionDropdown() {
document.getElementsByTagName('head')[0].appendChild(CSSLink);

var script = document.createElement('script');
const currentVersion = getCurrentVersion();
script.src = 'https://argo-cd.readthedocs.io/_/api/v2/footer_html/?' +
'callback=' + callbackName + '&project=argo-cd&page=&theme=mkdocs&format=jsonp&docroot=docs&source_suffix=.md&version=' + (window['READTHEDOCS_DATA'] || { version: 'latest' }).version;
'callback=' + callbackName + '&project=argo-cd&page=&theme=mkdocs&format=jsonp&docroot=docs&source_suffix=.md&version=' + (currentVersion || 'latest');
document.getElementsByTagName('head')[0].appendChild(script);
}

// VERSION WARNINGS
window.addEventListener("DOMContentLoaded", function() {
var currentVersion = window.location.href.match(/\/en\/(release-(?:v\d+|\w+)|latest|stable)\//);
var margin = 30;
var headerHeight = document.getElementsByClassName("md-header")[0].offsetHeight;
if (currentVersion && currentVersion.length > 1) {
currentVersion = currentVersion[1];
const currentVersion = getCurrentVersion();
if (currentVersion) {
if (currentVersion === "latest") {
document.querySelector("div[data-md-component=announce]").innerHTML = "<div id='announce-msg'>You are viewing the docs for an unreleased version of Argo CD, <a href='https://argo-cd.readthedocs.io/en/stable/'>click here to go to the latest stable version.</a></div>";
var bannerHeight = document.getElementById('announce-msg').offsetHeight + margin;
Expand All @@ -72,4 +80,4 @@ window.addEventListener("DOMContentLoaded", function() {
"@media screen and (min-width: 60em){ .md-sidebar--secondary { height: 0; top:" + (bannerHeight + headerHeight) + "px !important; }}";
}
}
});
});
Loading