jonschlinkert / gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert
https://github.com/jonschlinkert
MIT License
3.97k stars 138 forks source link

fails to read front matter with duplicate keys #28

Closed fitnr closed 8 years ago

fitnr commented 8 years ago

Given a file like this (test.html):


---
id: 1
foo: bar
foo: baz

---
> require('gray-matter').read('test.html')
{ orig: '---\nid: 1\nfoo: bar\nfoo: baz\n---',
  data: {},
  content: '',
  path: 'test.html' }

The data is completely empty because one key repeats. I would expect gray-matter to use the latest value in the front matter, or perhaps to throw an error.

jonschlinkert commented 8 years ago

Try setting options.strict to true, if that doesn't work we either need to improve error handling, or the issue is with js-yaml.

fitnr commented 8 years ago

Running with {strict: true} throws a YAMLException (duplicated mapping key). Thanks for the quick response.

jonschlinkert commented 8 years ago

no problem, thanks for using it

jonschlinkert commented 8 years ago

lol habit