Files
gitbook/lib/parse
Aaron O'Mullan c9db068227 Refactor navigation generation to be functional
This makes it a lot less error prone and far more robust. As well as a
lot easier to understand
2014-04-18 11:49:55 -07:00
..
2014-04-16 17:16:18 +02:00
2014-04-04 00:00:12 -07:00
2014-04-18 17:15:03 +02:00

var _ = require('lodash');
var marked = require('marked');

function extractFirstNode(nodes, nType) {
    return _.chain(nodes)
    .filter(function(node) {
        return node.type == nType;
    })
    .pluck("text")
    .first()
    .value();
}


function parseReadme(src) {
    var nodes, title, description;

    // Parse content
    nodes = marked.lexer(src);
    
    var title = extractFirstNode(nodes, "heading");
    var description = extractFirstNode(nodes, "paragraph");

    return {
        title: title,
        description: description
    };
}


// Exports
module.exports = parseReadme;