summaryrefslogtreecommitdiffstats
path: root/lib/parse/parsePage.js
blob: 1d515d6f696370238bceb824e7758ddd17220e72 (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
27
28
29
var Immutable = require('immutable');
var fm = require('front-matter');
var direction = require('direction');

/**
    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);

        return page.merge({
            content: parsed.body,
            attributes: Immutable.fromJS(parsed.attributes),
            dir: direction(parsed.body)
        });
    });
}


module.exports = parsePage;