Commit 202cc1a1 authored by Marcel Stör's avatar Marcel Stör
Browse files

Add meta-info block to every module doc page

parent 56843929
# WS2812 Module
| Since | Origin / Contributor | Maintainer | Source |
| :----- | :-------------------- | :---------- | :------ |
| 2015-02-05 | [Till Klocke](https://github.com/dereulenspiegel) | [Till Klocke](https://github.com/dereulenspiegel) | [ws2812.c](../../../app/modules/ws2812.c)|
## ws2812.write()
Send GRB data in 8 bits to a WS2812 chain.
......
......@@ -10,6 +10,7 @@ var nodemcu = nodemcu || {};
addToc();
hideNavigationForAllButSelectedLanguage();
addLanguageSelectorToRtdFlyOutMenu();
replaceRelativeLinksWithStaticGitHubUrl();
});
/**
......@@ -104,6 +105,20 @@ var nodemcu = nodemcu || {};
}
}
/**
* The module doc pages contain relative links to artifacts in the GitHub repository. For those links to work both
* on GitHub (i.e. when the page is viewed on GitHub) and on RTD they are defined with a relative URL. This function
* replaces the relative path with an absolute path based on the selected branch.
*/
function replaceRelativeLinksWithStaticGitHubUrl() {
var relativePath = "../../../..";
var gitHubPath = "https://github.com/nodemcu/nodemcu-firmware/tree/" + determineSelectedBranch();
var gitHubLinks = $("a[href^='" + relativePath + "']").each(function (index) {
var url = $(this).attr('href');
$(this).attr('href', url.replace(relativePath, gitHubPath));
});
}
function createLanguageLinkFor(languageCode, isCurrentlySelected) {
var strong;
// split[0] is an '' because the path starts with the separator
......@@ -146,6 +161,23 @@ var nodemcu = nodemcu || {};
return selectedLanguageCode;
}
/**
* Analyzes the URL of the current page to find out what the selected GitHub branch is. It's usually
* part of the location path. The code needs to distinguish between running MkDocs standalone
* and docs served from RTD. If no valid branch could be determined 'dev' returned.
*
* @returns GitHub branch name
*/
function determineSelectedBranch() {
var branch = 'dev', path = window.location.pathname;
if (window.location.origin.indexOf('readthedocs') > -1) {
// path is like /en/<branch>/<lang>/build/ -> extract 'lang'
// split[0] is an '' because the path starts with the separator
branch = path.split('/')[2];
}
return branch;
}
function values(associativeArray) {
var values = [];
for (var key in associativeArray) {
......
......@@ -57,10 +57,11 @@ pages:
- 'ow (1-Wire)': 'en/modules/ow.md'
- 'perf': 'en/modules/perf.md'
- 'pwm' : 'en/modules/pwm.md'
- 'rc' : 'en/modules/rc.md'
- 'rotary' : 'en/modules/rotary.md'
- 'rtcfifo': 'en/modules/rtcfifo.md'
- 'rtcmem': 'en/modules/rtcmem.md'
- 'rtctime': 'en/modules/rtctime.md'
- 'rtcfifo': 'en/modules/rtcfifo.md'
- 'sigma delta': 'en/modules/sigma-delta.md'
- 'sntp': 'en/modules/sntp.md'
- 'spi': 'en/modules/spi.md'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment