Rename DIR to dir and improve JavaScript for RTD

This commit is contained in:
Marcel Stör 2015-12-28 17:25:00 +01:00
parent 62320819fd
commit 3e68026d7b
11 changed files with 70 additions and 16 deletions

View File

@ -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). 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)

View File

@ -1,20 +1,17 @@
var nodemcu = nodemcu || {}; var nodemcu = nodemcu || {};
(function () { (function () {
'use strict'; 'use strict';
var languageCodeToNameMap = {EN: 'English', DE: 'Deutsch'}; var languageCodeToNameMap = {en: 'English', de: 'Deutsch'};
var languageNames = values(languageCodeToNameMap); var languageNames = values(languageCodeToNameMap);
var defaultLanguageCode = 'EN'; var defaultLanguageCode = 'en';
$(document).ready(function () { $(document).ready(function () {
hideNavigationForAllButSelectedLanguage(); hideNavigationForAllButSelectedLanguage();
addLanguageSelectorToRtdFlyOutMenu();
}); });
function hideNavigationForAllButSelectedLanguage() { function hideNavigationForAllButSelectedLanguage() {
// URL is like http://host/EN/build/ -> extract 'EN' var selectedLanguageCode = determineSelectedLanguageCode();
var selectedLanguageCode = window.location.pathname.substr(1, 2);
if (!selectedLanguageCode) {
selectedLanguageCode = defaultLanguageCode;
}
var selectedLanguageName = languageCodeToNameMap[selectedLanguageCode]; var selectedLanguageName = languageCodeToNameMap[selectedLanguageCode];
// Finds all subnav elements and hides them if they're /language/ subnavs. Hence, all 'Modules' subnav elements // Finds all subnav elements and hides them if they're /language/ subnavs. Hence, all 'Modules' subnav elements
// won't be hidden. // 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
* <dl>
* <dt>Languages</dt>
* <dd><a href="http://nodemcu.readthedocs.org/en/<branch>/de/">de</a></dd>
* <strong>
* <dd><a href="http://nodemcu.readthedocs.org/en/<branch>/en/">en</a></dd>
* </strong>
* </dl>
*/
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/<branch>/<lang>/build/ -> extract 'lang'
selectedLanguageCode = path.split('/')[2];
} else {
// path is like /<lang>/build/ -> extract 'lang'
selectedLanguageCode = path.substr(1, 2);
}
if (!selectedLanguageCode || selectedLanguageCode.length > 2) {
selectedLanguageCode = defaultLanguageCode;
}
return selectedLanguageCode;
}
function values(associativeArray) { function values(associativeArray) {
var values = []; var values = [];
for (var key in associativeArray) { for (var key in associativeArray) {

View File

@ -23,12 +23,12 @@ site_favicon: img/favicon.png
pages: pages:
- Overview: 'index.md' - Overview: 'index.md'
- English: - English:
- Home: 'EN/index.md' - Home: 'en/index.md'
- Building the firmware: 'EN/build.md' - Building the firmware: 'en/build.md'
- Flashing the firmware: 'EN/flash.md' - Flashing the firmware: 'en/flash.md'
- FAQ: 'EN/faq.md' - FAQ: 'en/faq.md'
- Support: 'EN/support.md' - Support: 'en/support.md'
- Modules: - Modules:
- 'node': 'EN/modules/node.md' - 'node': 'en/modules/node.md'
- Deutsch: - Deutsch:
- Home: 'DE/index.md' - Home: 'de/index.md'