diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-06-07 14:32:12 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-06-07 14:32:12 +0200 |
commit | f1d200b81be9b09b994db9acdc2671cd941912d4 (patch) | |
tree | 829e0fd43fc2b88f105eb90a5cf57449bf83f939 /lib | |
parent | b566711ee1caedbafa1d613b05f011e781a78bd2 (diff) | |
download | gitbook-f1d200b81be9b09b994db9acdc2671cd941912d4.zip gitbook-f1d200b81be9b09b994db9acdc2671cd941912d4.tar.gz gitbook-f1d200b81be9b09b994db9acdc2671cd941912d4.tar.bz2 |
Rollback frontmatter parsing to js-yaml to be browserify compatible
Diffstat (limited to 'lib')
-rw-r--r-- | lib/models/__tests__/page.js | 2 | ||||
-rw-r--r-- | lib/models/page.js | 5 | ||||
-rw-r--r-- | lib/parse/parsePageFromString.js | 10 |
3 files changed, 9 insertions, 8 deletions
diff --git a/lib/models/__tests__/page.js b/lib/models/__tests__/page.js index 15a13ad..e75f8a8 100644 --- a/lib/models/__tests__/page.js +++ b/lib/models/__tests__/page.js @@ -20,7 +20,7 @@ describe('Page', function() { }) }); - expect(page.toText()).toBe('---\nhello: world\n---\nHello World\n'); + expect(page.toText()).toBe('---\nhello: world\n---\nHello World'); }); }); }); diff --git a/lib/models/page.js b/lib/models/page.js index 3f54f43..43a2c1f 100644 --- a/lib/models/page.js +++ b/lib/models/page.js @@ -1,5 +1,5 @@ var Immutable = require('immutable'); -var matter = require('gray-matter'); +var yaml = require('js-yaml');; var File = require('./file'); @@ -44,7 +44,8 @@ Page.prototype.toText = function() { return content; } - return matter.stringify(content, attrs.toJS()); + var frontMatter = '---\n' + yaml.safeDump(attrs.toJS(), { skipInvalid: true }) + '---\n'; + return (frontMatter + content); }; /** diff --git a/lib/parse/parsePageFromString.js b/lib/parse/parsePageFromString.js index 2e0c48c..80c147b 100644 --- a/lib/parse/parsePageFromString.js +++ b/lib/parse/parsePageFromString.js @@ -1,5 +1,5 @@ var Immutable = require('immutable'); -var matter = require('gray-matter'); +var fm = require('front-matter'); var direction = require('direction'); /** @@ -9,12 +9,12 @@ var direction = require('direction'); * @return {Page} */ function parsePageFromString(page, content) { - var parsed = matter(content); + var parsed = fm(content); return page.merge({ - content: parsed.content, - attributes: Immutable.fromJS(parsed.data), - dir: direction(parsed.content) + content: parsed.body, + attributes: Immutable.fromJS(parsed.attributes), + dir: direction(parsed.body) }); } |