Skip to content

Commit

Permalink
fix persist with missing body from file
Browse files Browse the repository at this point in the history
  • Loading branch information
ebello authored and tech4him1 committed Nov 11, 2017
1 parent 495e7c8 commit 0183ad4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/formats/__tests__/frontmatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
});
});
2 changes: 1 addition & 1 deletion src/formats/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0183ad4

Please sign in to comment.