diff --git a/src/formats/__tests__/frontmatter.spec.js b/src/formats/__tests__/frontmatter.spec.js index 9a9c26eb..c88339a6 100644 --- a/src/formats/__tests__/frontmatter.spec.js +++ b/src/formats/__tests__/frontmatter.spec.js @@ -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') + ); + }); }); diff --git a/src/formats/frontmatter.js b/src/formats/frontmatter.js index 620ee090..6953c224 100644 --- a/src/formats/frontmatter.js +++ b/src/formats/frontmatter.js @@ -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