add Try new Docs button in the current docs

Signed-off-by: Artem Navoiev <tenmozes@gmail.com>
This commit is contained in:
Artem Navoiev 2023-11-01 17:22:49 +01:00
parent da887b49e7
commit 324ecbeed6
No known key found for this signature in database
GPG key ID: BE7B8368E3432014
2 changed files with 35 additions and 5 deletions

View file

@ -10,19 +10,36 @@ window.addEventListener("load", function () {
href = hash
}
const sidebar = document.querySelector('.sidebar .toctree');
const selector = function(href) {return `a[href="${href}"]`};
const selector = function (href) {
return `a[href="${href}"]`
};
let element = sidebar.querySelector(selector(href));
if (!element) {
href = window.location.pathname;
element = document.querySelector(selector(href));
}
if (element) {
element.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" });
element.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
}
addNewDocsButton()
});
function addNewDocsButton() {
let navigationBox = document.querySelector(".navigation-top");
if (navigationBox) {
let newDocsButton = document.createElement('a');
newDocsButton.appendChild(document.createTextNode("Try New Docs"));
newDocsButton.className = "btn";
newDocsButton.title = "Try New Docs";
newDocsButton.href = "https://new.docs.victoriametrics.com";
let lastA = document.querySelector(".navigation-top > a");
if (lastA) {
lastA.parentNode.insertBefore(newDocsButton, lastA);
}
}
}
$(document).on("click", '.shift li.toc a', function(e) {
$(document).on("click", '.shift li.toc a', function (e) {
let segments = this.href.split('#');
if (segments.length < 2) {
/* ignore links without anchor */
@ -32,8 +49,8 @@ $(document).on("click", '.shift li.toc a', function(e) {
e.preventDefault();
$("#toggle").click();
setTimeout(function () {
location.hash = segments.pop();
},1)
location.hash = segments.pop();
}, 1)
});
/* Clipboard-copy snippet from https://github.com/marcoaugustoandrade/jekyll-clipboardjs/blob/master/copy.js */

View file

@ -49,3 +49,16 @@
.markdown-body h4 {
font-family: 'Lato', sans-serif !important;
}
// try new page button
.navigation-top {
min-height: 32px;
}
.navigation-top > a:last-child{
padding-left: 5px
}
.navigation-top > .btn {
margin-left: auto
}