fix adds support for Flatdoc.file([ 'file1.md', 'file2.md' ])
for now.
Flatdoc.file = function(locations) {
function loadData(locations, response, callback) {
if (locations.length === 0) callback(null, response);
else $.get(locations.shift()).done(function (data) {
loadData(locations, response + data, callback);
}).fail(function(data) {
callback(data, null)
});
}
return function(callback) {
loadData(locations instanceof Array ? locations : [locations], '', callback);
}
};
<script>
var combined='';
Flatdoc.file = function(url) {
return function(callback) {
callback(null, combined);
};
};
var get0=function() {
url='00-Intro.md';
$.get(url).fail(function(e) { alert("fail"); })
.done(get1);
};
var get1=function(data) {
combined+=data;
url='01-First.md';
$.get(url).fail(function(e) { alert("fail"); })
.done(get2);
};
var get2=function(data) {
combined+=data;
url='02-Second.md';
$.get(url).fail(function(e) { alert("fail"); })
.done(getX);
};
var getX=function(data) {
combined+=data;
Flatdoc.run({
fetcher: Flatdoc.file("")
});
};
get0();
</script>
Iโve modified the Flatdoc.github fetcher to handle fetching a directory listing โ it will fetch all the markdown files in that directory and concatenate them. This keeps the API easy to use (see below).
Assuming I have a github repo with the following files:
- docs
\- 01-intro.md
- 02-main_documentation.md
- 03-contributing.md
- 04-license.md
and load the documentation in FlatDoc as follows:
Flatdoc.run({
fetcher: Flatdoc.github('me/myrepo', 'docs')
});
Then flatdoc will fetch the directory listing for docs , then will fetch all of the markdown files in alphabetical order and concatenate them.
Katie.