From dec93431cf74ab5bb113ef67ccc5018bbe2aa663 Mon Sep 17 00:00:00 2001 From: Guillaume Brioudes Date: Mon, 2 Dec 2024 19:00:54 +0100 Subject: [PATCH] fix: yaml frontmatter --- core/utils/yamlfrontmatter.js | 4 ++-- core/utils/yamlfrontmatter.spec.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/utils/yamlfrontmatter.js b/core/utils/yamlfrontmatter.js index 82e67301..a454c42f 100644 --- a/core/utils/yamlfrontmatter.js +++ b/core/utils/yamlfrontmatter.js @@ -7,7 +7,7 @@ const regex = /^(-{3}(?:\n|\r)([\w\W]+?)(?:\n|\r)[-|\.]{3})?([\w\W]*)*/; * Read head of markdown files as YAML content * Get result as JSON * @param {string} fileContent - * @param {object} options https://eemeli.org/yaml/#options + * @param {import('yaml').ParseOptions & import('yaml').SchemaOptions} options * @returns {{head: unknown, content: string}} JSON */ @@ -19,7 +19,7 @@ function read(fileContent, options = {}) { let ymlResult = {}; - if (!!fileContent) { + if (fileContent && withoutDash) { ymlResult = yml.parse(withoutDash, options); } diff --git a/core/utils/yamlfrontmatter.spec.js b/core/utils/yamlfrontmatter.spec.js index 7bc4792d..2ffc3459 100644 --- a/core/utils/yamlfrontmatter.spec.js +++ b/core/utils/yamlfrontmatter.spec.js @@ -41,6 +41,14 @@ Paul Otlet est la tĂȘte pensante du Mundaneum`, }, description: 'Empty', }, + { + input: 'No Yaml Front Matter', + expected: { + content: 'No Yaml Front Matter', + head: {}, + }, + description: 'No head', + }, ]; describe('YAML Front Matter parser', function () {