From 3e68026d7bd20339f7076e473f50219216b313da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Mon, 28 Dec 2015 17:25:00 +0100 Subject: [PATCH] Rename DIR to dir and improve JavaScript for RTD --- docs/{DE => de}/index.md | 0 docs/{EN => en}/build.md | 0 docs/{EN => en}/faq.md | 0 docs/{EN => en}/flash.md | 0 docs/{EN => en}/index.md | 0 docs/{EN => en}/modules/node.md | 0 docs/{EN => en}/start.md | 0 docs/{EN => en}/support.md | 0 docs/index.md | 4 +- docs/js/extra.js | 68 +++++++++++++++++++++++++++++---- mkdocs.yml | 14 +++---- 11 files changed, 70 insertions(+), 16 deletions(-) rename docs/{DE => de}/index.md (100%) rename docs/{EN => en}/build.md (100%) rename docs/{EN => en}/faq.md (100%) rename docs/{EN => en}/flash.md (100%) rename docs/{EN => en}/index.md (100%) rename docs/{EN => en}/modules/node.md (100%) rename docs/{EN => en}/start.md (100%) rename docs/{EN => en}/support.md (100%) diff --git a/docs/DE/index.md b/docs/de/index.md similarity index 100% rename from docs/DE/index.md rename to docs/de/index.md diff --git a/docs/EN/build.md b/docs/en/build.md similarity index 100% rename from docs/EN/build.md rename to docs/en/build.md diff --git a/docs/EN/faq.md b/docs/en/faq.md similarity index 100% rename from docs/EN/faq.md rename to docs/en/faq.md diff --git a/docs/EN/flash.md b/docs/en/flash.md similarity index 100% rename from docs/EN/flash.md rename to docs/en/flash.md diff --git a/docs/EN/index.md b/docs/en/index.md similarity index 100% rename from docs/EN/index.md rename to docs/en/index.md diff --git a/docs/EN/modules/node.md b/docs/en/modules/node.md similarity index 100% rename from docs/EN/modules/node.md rename to docs/en/modules/node.md diff --git a/docs/EN/start.md b/docs/en/start.md similarity index 100% rename from docs/EN/start.md rename to docs/en/start.md diff --git a/docs/EN/support.md b/docs/en/support.md similarity index 100% rename from docs/EN/support.md rename to docs/en/support.md diff --git a/docs/index.md b/docs/index.md index a300ef43..1ee20244 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,7 +4,7 @@ NodeMCU is an [eLua](http://www.eluaproject.net/) based firmware for the [ESP826 The firmware is based on the Espressif SDK v1.4 and uses a file system based on [spiffs](https://github.com/pellepl/spiffs). -[English](EN/index.md) +[English](en/index.md) -[Deutsch](DE/index.md) +[Deutsch](de/index.md) diff --git a/docs/js/extra.js b/docs/js/extra.js index 83e680eb..45ffeb50 100644 --- a/docs/js/extra.js +++ b/docs/js/extra.js @@ -1,20 +1,17 @@ var nodemcu = nodemcu || {}; (function () { 'use strict'; - var languageCodeToNameMap = {EN: 'English', DE: 'Deutsch'}; + var languageCodeToNameMap = {en: 'English', de: 'Deutsch'}; var languageNames = values(languageCodeToNameMap); - var defaultLanguageCode = 'EN'; + var defaultLanguageCode = 'en'; $(document).ready(function () { hideNavigationForAllButSelectedLanguage(); + addLanguageSelectorToRtdFlyOutMenu(); }); function hideNavigationForAllButSelectedLanguage() { - // URL is like http://host/EN/build/ -> extract 'EN' - var selectedLanguageCode = window.location.pathname.substr(1, 2); - if (!selectedLanguageCode) { - selectedLanguageCode = defaultLanguageCode; - } + var selectedLanguageCode = determineSelectedLanguageCode(); var selectedLanguageName = languageCodeToNameMap[selectedLanguageCode]; // Finds all subnav elements and hides them if they're /language/ subnavs. Hence, all 'Modules' subnav elements // won't be hidden. @@ -31,6 +28,63 @@ var nodemcu = nodemcu || {}; }); } + /** + * Adds a language selector to the RTD fly out menu found bottom left. Example + *
+ *
Languages
+ *
de
+ * + *
en
+ *
+ *
+ */ + function addLanguageSelectorToRtdFlyOutMenu() { + var flyOutWrapper = $('.rst-other-versions .injected'); + // only works on RTD + if (flyOutWrapper.length > 0) { + var selectedLanguageCode = determineSelectedLanguageCode(); + var dl = document.createElement('dl'); + var dt = document.createElement('dt'); + dl.appendChild(dt); + dt.appendChild(document.createTextNode('Languages')); + for (var languageCode in languageCodeToNameMap) { + dl.appendChild(createLanguageLinkFor(languageCode, selectedLanguageCode === languageCode)); + } + flyOutWrapper.prepend(dl); + } + } + function createLanguageLinkFor(languageCode, isCurrentlySelected) { + var strong; + var pathSegments = window.location.pathname.split('/'); + var dd = document.createElement("dd"); + var href = document.createElement("href"); + href.setAttribute('a', '/' + pathSegments[0] + '/' + pathSegments[1] + '/' + languageCode); + href.appendChild(document.createTextNode(languageCode)); + dd.appendChild(href); + if (isCurrentlySelected) { + strong = document.createElement("strong"); + strong.appendChild(dd); + return strong; + } else { + return dd; + } + } + + function determineSelectedLanguageCode() { + var selectedLanguageCode, path = window.location.pathname; + if (window.location.origin.indexOf('readthedocs') > -1) { + // path is like /en///build/ -> extract 'lang' + selectedLanguageCode = path.split('/')[2]; + } else { + // path is like //build/ -> extract 'lang' + selectedLanguageCode = path.substr(1, 2); + } + if (!selectedLanguageCode || selectedLanguageCode.length > 2) { + selectedLanguageCode = defaultLanguageCode; + } + return selectedLanguageCode; + } + function values(associativeArray) { var values = []; for (var key in associativeArray) { diff --git a/mkdocs.yml b/mkdocs.yml index 5df98e60..3ed7531b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -23,12 +23,12 @@ site_favicon: img/favicon.png pages: - Overview: 'index.md' - English: - - Home: 'EN/index.md' - - Building the firmware: 'EN/build.md' - - Flashing the firmware: 'EN/flash.md' - - FAQ: 'EN/faq.md' - - Support: 'EN/support.md' + - Home: 'en/index.md' + - Building the firmware: 'en/build.md' + - Flashing the firmware: 'en/flash.md' + - FAQ: 'en/faq.md' + - Support: 'en/support.md' - Modules: - - 'node': 'EN/modules/node.md' + - 'node': 'en/modules/node.md' - Deutsch: - - Home: 'DE/index.md' \ No newline at end of file + - Home: 'de/index.md' \ No newline at end of file