diff --git a/core/utils/yamlfrontmatter.js b/core/utils/yamlfrontmatter.js index 82e6730..a454c42 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 7bc4792..2ffc345 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 () {