ilterra / markdown-yaml-metadata-parser

Parse YAML metadata (front matter) in a markdown document

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Metadata are not parsed when content does not exist

pkonieczniak opened this issue · comments

Input:

const path = join(tmpdir(), 'markdown.md')
const content = '---\ntitle: fake title\nauthor: fooBar\n---'
fs.writeFileSync(path, content)
  
const source = fs.readFileSync(path, 'utf8')
const result = markdownParser(source)
console.log(result)

Result:

{ 
  metadata: {},
  content: '---\ntitle: fake title\nauthor: fooBar\n---' 
}

Works fine when content is defined.
Input:

 const path = join(tmpdir(), 'markdown.md')
 const content = '---\ntitle: fake title\nauthor: fooBar\n---\nContent goes here'
 fs.writeFileSync(path, content)
  
 const source = fs.readFileSync(path, 'utf8')
 const result = markdownParser(source)
 console.log(result)

Result:

{ 
  metadata: { title: 'fake Title', author: 'fooBar' },
  content: 'Content goes here' 
}

I've released version 2.0.1 which covers also this use case.