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.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/parse/parsePage.js b/lib/parse/parsePage.js
new file mode 100644
index 0000000..75bcf61
--- /dev/null
+++ b/lib/parse/parsePage.js
@@ -0,0 +1,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;