// These three variables below need to be updated at each release for the selectors. const languages = [ "rust", "python", "node" ]; // Last stable version for each language const stableVersion = { "rust": "master", "python": "v0.9.0", "node": "master" } // Dictionary doc folder to Label for each language const versionMapping = { "rust": { "master": "master", }, "python": { "master": "master", "v0.9.0": "v0.9.0" }, "node": { "master": "master", } }; // Dictionnary language name to Label const languageName = { "rust": "Rust", "python": "Python", "node": "Node.js" }; const defaultLanguage = "python"; function addIcon() { const huggingFaceLogo = "https://huggingface.co/landing/assets/transformers-docs/huggingface_logo.svg"; const image = document.createElement("img"); image.setAttribute("src", huggingFaceLogo); const div = document.createElement("div"); div.appendChild(image); div.style.textAlign = 'center'; div.style.paddingTop = '30px'; div.style.backgroundColor = '#6670FF'; const scrollDiv = document.querySelector(".wy-side-scroll"); scrollDiv.prepend(div); } function addCustomFooter() { const customFooter = document.createElement("div"); const questionOrIssue = document.createElement("div"); questionOrIssue.innerHTML = "Stuck? Read our Blog posts" + " or Create an issue"; customFooter.appendChild(questionOrIssue); customFooter.classList.add("footer"); const social = document.createElement("div"); social.classList.add("footer__Social"); const imageDetails = [ { link: "https://huggingface.co", imageLink: "https://huggingface.co/landing/assets/transformers-docs/website.svg" }, { link: "https://twitter.com/huggingface", imageLink: "https://huggingface.co/landing/assets/transformers-docs/twitter.svg" }, { link: "https://github.com/huggingface", imageLink: "https://huggingface.co/landing/assets/transformers-docs/github.svg" }, { link: "https://www.linkedin.com/company/huggingface/", imageLink: "https://huggingface.co/landing/assets/transformers-docs/linkedin.svg" } ]; imageDetails.forEach(imageLinks => { const link = document.createElement("a"); const image = document.createElement("img"); image.src = imageLinks.imageLink; link.href = imageLinks.link; image.style.width = "30px"; image.classList.add("footer__CustomImage"); link.appendChild(image); social.appendChild(link); }); customFooter.appendChild(social); document.querySelector("footer").appendChild(customFooter); } function addGithubButton() { const div = `
`; document.querySelector(".wy-side-nav-search .icon-home").insertAdjacentHTML('afterend', div); } function addVersionControl() { // Default language and version let language = defaultLanguage; let version = stableVersion[language]; // To grab the version currently in view, we parse the url let parts = location.pathname.split('/'); const languageIndex = parts.findIndex((part) => languages.includes(part)); language = parts[languageIndex]; const versionIndex = languageIndex + 1; // If a version is specified, update it if (parts[versionIndex] != "" && !parts[versionIndex].endsWith(".html")) { // If `latest`, let's keep the default (should be the explicit latest version) if (parts[versionIndex] != "latest") { version = parts[versionIndex]; } // Otherwise redirect to the latest (if not opening locally) } else if (!parts[parts.length - 1].endsWith(".html")) { return window.location.pathname = [language, version, parts.splice(versionIndex)].join("/"); // Opening locally, just don't show the version/language selector } else { return } // Language Menu const languageMenu = document.createElement("div"); languageMenu.classList.add("menu-dropdown"); languageMenu.innerHTML = languages.map((lang) => { let updatedParts = parts.map((l, i) => { if (i == languageIndex) { return lang; } else { return l; } }); return ` ${languageName[lang]} `; }).join("\n"); // Version Menu const versionMenu = document.createElement("div"); versionMenu.classList.add("menu-dropdown"); versionMenu.innerHTML = Object.entries(versionMapping[language]).map(([key, value]) => { let updatedParts = parts.map((v, i) => { if (i == versionIndex) { return key; } else { return v } }); return ` ${value} `; }).join("\n"); // Language button const languageButton = document.createElement("div"); languageButton.classList.add("dropdown-button"); languageButton.innerText = languageName[language].concat(" âŒ"); languageButton.addEventListener("click", () => { versionMenu.classList.remove("show"); languageMenu.classList.toggle("show"); languageButton.classList.toggle("active"); }); // Button for version selection const versionButton = document.createElement("div"); versionButton.classList.add("dropdown-button"); versionButton.innerText = version.concat(" âŒ"); // Toggle the menu when we click on the button versionButton.addEventListener("click", () => { languageMenu.classList.remove("show"); versionMenu.classList.toggle("show"); versionButton.classList.toggle("active"); }); // Hide the menu when we click elsewhere window.addEventListener("click", (event) => { if (event.target != languageButton){ languageButton.classList.remove('active'); languageMenu.classList.remove('show'); } if (event.target != versionButton){ versionButton.classList.remove('active'); versionMenu.classList.remove('show'); } }); const buttonContainer = document.createElement("div"); buttonContainer.classList.add("button-container"); buttonContainer.appendChild(languageButton); buttonContainer.appendChild(versionButton); // Container const div = document.createElement("div"); div.classList.add("selectors"); div.appendChild(buttonContainer); div.appendChild(languageMenu); div.appendChild(versionMenu); div.style.paddingTop = '25px'; div.style.backgroundColor = '#6670FF'; div.style.display = 'block'; div.style.textAlign = 'center'; const scrollDiv = document.querySelector(".wy-side-scroll"); scrollDiv.insertBefore(div, scrollDiv.children[1]); } function addHfMenu() { const div = ` `; document.body.insertAdjacentHTML('afterbegin', div); } /*! * github-buttons v2.2.10 * (c) 2019 ăȘă€ă * @license BSD-2-Clause */ /** * modified to run programmatically */ function parseGithubButtons (){"use strict";var e=window.document,t=e.location,o=window.encodeURIComponent,r=window.decodeURIComponent,n=window.Math,a=window.HTMLElement,i=window.XMLHttpRequest,l="https://unpkg.com/github-buttons@2.2.10/dist/buttons.html",c=i&&i.prototype&&"withCredentials"in i.prototype,d=c&&a&&a.prototype.attachShadow&&!a.prototype.attachShadow.prototype,s=function(e,t,o){e.addEventListener?e.addEventListener(t,o):e.attachEvent("on"+t,o)},u=function(e,t,o){e.removeEventListener?e.removeEventListener(t,o):e.detachEvent("on"+t,o)},h=function(e,t,o){var r=function(n){return u(e,t,r),o(n)};s(e,t,r)},f=function(e,t,o){var r=function(n){if(t.test(e.readyState))return u(e,"readystatechange",r),o(n)};s(e,"readystatechange",r)},p=function(e){return function(t,o,r){var n=e.createElement(t);if(o)for(var a in o){var i=o[a];null!=i&&(null!=n[a]?n[a]=i:n.setAttribute(a,i))}if(r)for(var l=0,c=r.length;l