Skip to content

Instantly share code, notes, and snippets.

@roachhd
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roachhd/bfe9310930d5dfd8a888 to your computer and use it in GitHub Desktop.
Save roachhd/bfe9310930d5dfd8a888 to your computer and use it in GitHub Desktop.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment