Skip to content

Commit 0183ad4

Browse files
ebellotech4him1
authored andcommitted
fix persist with missing body from file
1 parent 495e7c8 commit 0183ad4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/formats/__tests__/frontmatter.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,21 @@ describe('Frontmatter', () => {
102102
].join('\n')
103103
);
104104
});
105+
106+
it('should stringify YAML with missing body', () => {
107+
expect(
108+
FrontmatterFormatter.toFile({ tags: ['front matter', 'yaml'], title: 'YAML' })
109+
).toEqual(
110+
[
111+
'---',
112+
'tags:',
113+
' - front matter',
114+
' - yaml',
115+
'title: YAML',
116+
'---',
117+
'',
118+
'',
119+
].join('\n')
120+
);
121+
});
105122
});

src/formats/frontmatter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default {
5050
},
5151

5252
toFile(data, sortedKeys) {
53-
const { body, ...meta } = data;
53+
const { body = '', ...meta } = data;
5454

5555
// always stringify to YAML
5656
// `sortedKeys` is not recognized by gray-matter, so it gets passed through to the parser

0 commit comments

Comments
 (0)