From 80673e0d52c8ef99abfc8fcc5a6ed9629f92f137 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 11 Dec 2024 11:02:07 +0100 Subject: [PATCH] fix(stringify): empty line between frontmatter and content --- src/frontmatter.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/frontmatter.ts b/src/frontmatter.ts index af0f713..4d3b4a0 100644 --- a/src/frontmatter.ts +++ b/src/frontmatter.ts @@ -6,17 +6,23 @@ const FRONTMATTER_DELIMITER_CODEBLOCK_STYLE = '```yaml [props]' export function stringifyFrontMatter(data: any, content = '') { if (!Object.keys(data).length) { - return '' + return content.trim() } data = flat.unflatten(data || {}, {}) - return [ + const frontmatter = [ FRONTMATTER_DELIMITER_DEFAULT, stringify(data).trim(), FRONTMATTER_DELIMITER_DEFAULT, - content, + '', ].join('\n') + + if (content) { + return [frontmatter, content.trim(), ''].join('\n') + } + + return frontmatter } export function stringifyCodeBlockProps(data: any, content = '') {