Files
gitbook/lib/parse/parsePage.js
T
2016-04-23 17:10:16 +02:00

30 lines
676 B
JavaScript

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;