fix persist with missing body from file

This commit is contained in:
Ernie Bello 2017-11-11 15:52:02 -05:00 committed by Caleb
parent 495e7c8743
commit 0183ad433b
2 changed files with 18 additions and 1 deletions

View File

@ -102,4 +102,21 @@ describe('Frontmatter', () => {
].join('\n')
);
});
it('should stringify YAML with missing body', () => {
expect(
FrontmatterFormatter.toFile({ tags: ['front matter', 'yaml'], title: 'YAML' })
).toEqual(
[
'---',
'tags:',
' - front matter',
' - yaml',
'title: YAML',
'---',
'',
'',
].join('\n')
);
});
});

View File

@ -50,7 +50,7 @@ export default {
},
toFile(data, sortedKeys) {
const { body, ...meta } = data;
const { body = '', ...meta } = data;
// always stringify to YAML
// `sortedKeys` is not recognized by gray-matter, so it gets passed through to the parser