Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix persist with missing body from file (regression from #759) #808

Merged
merged 1 commit into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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