From 6894b486d0486bd813af24fb4c27c4f5775e5fd8 Mon Sep 17 00:00:00 2001 From: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Date: Wed, 24 Jun 2020 12:13:43 -0400 Subject: [PATCH] Fix version controller links (for realsies) (#5251) --- docs/source/_static/js/custom.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/source/_static/js/custom.js b/docs/source/_static/js/custom.js index fc2dd6b3c2..7aceddbe21 100644 --- a/docs/source/_static/js/custom.js +++ b/docs/source/_static/js/custom.js @@ -84,14 +84,14 @@ function addGithubButton() { function addVersionControl() { // To grab the version currently in view, we parse the url const parts = location.toString().split('/'); - let versionIndex = parts.length - 2 + let versionIndex = parts.length - 2; // Index page may not have a last part with filename.html so we need to go up - if (! parts[versionIndex].match(/\.html$/)) { - versionIndex = parts.length - 1 + if (parts[parts.length - 1] != "" && ! parts[parts.length - 1].match(/\.html$/)) { + versionIndex = parts.length - 1; } // Main classes and models are nested so we need to go deeper else if (parts[versionIndex] == "main_classes" || parts[versionIndex] == "model_doc") { - versionIndex = parts.length - 3 + versionIndex = versionIndex - 1; } const version = parts[versionIndex]; @@ -100,11 +100,12 @@ function addVersionControl() { const htmlLines = []; for (const [key, value] of Object.entries(versionMapping)) { - var urlParts = parts.slice(0, versionIndex-1); + let baseUrlIndex = (version == "transformers") ? versionIndex + 1: versionIndex; + var urlParts = parts.slice(0, baseUrlIndex); if (key != "") { urlParts = urlParts.concat([key]); } - urlParts = urlParts.concat(parts.slice(versionIndex)); + urlParts = urlParts.concat(parts.slice(versionIndex+1)); htmlLines.push(`${value}`); }