From 4f48ee9871fcab7186c7b89a3fa49b7d78204d5a Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 17 Oct 2021 21:48:38 +0300 Subject: [PATCH 1/2] fix R API link to point to the current version of docs --- docs/_static/js/script.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/_static/js/script.js b/docs/_static/js/script.js index d990dc558b70..1b3816b995c8 100644 --- a/docs/_static/js/script.js +++ b/docs/_static/js/script.js @@ -2,12 +2,30 @@ $(function() { /* Use wider container for the page content */ $('.wy-nav-content').each(function() { this.style.setProperty('max-width', 'none', 'important'); }); + /* Point to the same version of R API as the current docs version */ + var current_version_elems = $('.rst-current-version'); + if(current_version_elems.length !== 0) { + var current_version = $(current_version_elems[0]).contents().filter(function() { + return this.nodeType == 3; + }).text().trim().split(' ').pop(); + $('a.reference.external[href$="/latest/R/reference/"]').each(function() { + $(this).attr('href', function (_, val) { return val.replace('/latest/', '/' + current_version + '/'); }); + }); + } + /* Collapse specified sections in the installation guide */ if(window.location.pathname.toLocaleLowerCase().indexOf('installation-guide') != -1) { $('').appendTo('body'); - var collapsable = ['#build-threadless-version-not-recommended', '#build-mpi-version', '#build-gpu-version', - '#build-cuda-version-experimental', '#build-hdfs-version', '#build-java-wrapper', '#build-c-unit-tests']; - $.each(collapsable, function(i, val) { + var collapsable = [ + '#build-threadless-version-not-recommended', + '#build-mpi-version', + '#build-gpu-version', + '#build-cuda-version-experimental', + '#build-hdfs-version', + '#build-java-wrapper', + '#build-c-unit-tests' + ]; + $.each(collapsable, function(_, val) { var header = val + ' > :header:first'; var content = val + ' :not(:header:first)'; $(header).addClass('closed'); @@ -19,7 +37,7 @@ $(function() { }); /* Uncollapse parent sections when nested section is specified in the URL or before navigate to it from navbar */ function uncollapse(section) { - section.parents().each((i, val) => { $(val).children('.closed').click(); }); + section.parents().each((_, val) => { $(val).children('.closed').click(); }); } uncollapse($(window.location.hash)); $('.wy-menu.wy-menu-vertical li a.reference.internal').click(function() { From 9a53e9936bdd15e33b5a9e1cc59df92c96d5330e Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Mon, 18 Oct 2021 00:25:52 +0300 Subject: [PATCH 2/2] speedup --- docs/_static/js/script.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/_static/js/script.js b/docs/_static/js/script.js index 1b3816b995c8..f3e59258f53b 100644 --- a/docs/_static/js/script.js +++ b/docs/_static/js/script.js @@ -8,9 +8,11 @@ $(function() { var current_version = $(current_version_elems[0]).contents().filter(function() { return this.nodeType == 3; }).text().trim().split(' ').pop(); - $('a.reference.external[href$="/latest/R/reference/"]').each(function() { - $(this).attr('href', function (_, val) { return val.replace('/latest/', '/' + current_version + '/'); }); - }); + if(current_version !== 'latest') { + $('a.reference.external[href$="/latest/R/reference/"]').each(function() { + $(this).attr('href', function (_, val) { return val.replace('/latest/', '/' + current_version + '/'); }); + }); + } } /* Collapse specified sections in the installation guide */