summaryrefslogtreecommitdiffstats
path: root/lib/parse/parsePage.js
blob: 75bcf61543510ffd2cd6a236198eee6eddcbabe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var fm = require('front-matter');

/**
    Parse a page, read its content and parse the YAMl header

    @param {Book} book
    @param {Page} page
    @return {Promise<Page>}
*/
function parsePage(book, page) {
    var fs = book.getContentFS();
    var file = page.getFile();

    return fs.readAsString(file.getPath())
    .then(function(content) {
        var parsed = fm(content);

        page = page.set('content', parsed.body);
        page = page.set('attributes', parsed.attributes);

        return page;
    });
}


module.exports = parsePage;