summaryrefslogtreecommitdiffstats
path: root/lib/parse/parsePage.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse/parsePage.js')
-rw-r--r--lib/parse/parsePage.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/parse/parsePage.js b/lib/parse/parsePage.js
new file mode 100644
index 0000000..1d515d6
--- /dev/null
+++ b/lib/parse/parsePage.js
@@ -0,0 +1,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;