block by roachhd bfe9310930d5dfd8a888

FLATSOC TESTS: INCLUDE MULTIPLE MD FILES IN ONE INDEX.HTML

Multiple markdown files to FlatDoc

fix adds support for Flatdoc.file([ 'file1.md', 'file2.md' ]) for now.

all cleaned & approved for use ๐Ÿ˜‰

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);
        }
      };

First messy way, donโ€™t user this reality, apps has now been approved.

  <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>

another solution - possibly

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.