From 0183ad433b7f141625f75617f8e6c651489b2897 Mon Sep 17 00:00:00 2001 From: Ernie Bello Date: Sat, 11 Nov 2017 15:52:02 -0500 Subject: [PATCH] fix persist with missing body from file --- src/formats/__tests__/frontmatter.spec.js | 17 +++++++++++++++++ src/formats/frontmatter.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) 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