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

is there any fancy way to edit gray-matter data in nodejs #122

Closed Yrobot closed 3 years ago

Yrobot commented 3 years ago

gray-matter can read matter-data from markdown file. but when i want to update the matter-data in nodejs file, i am confused. is there decent way to do so?

doowb commented 3 years ago

Have you tried the .stringify method? Here's an example

Yrobot commented 3 years ago

Have you tried the .stringify method? Here's an example

oops!!!!! .stringfly works fine.

I create a package yestoday called gray-matter-editor, with which we can update file matter-data in one function. editor will auto write matter-data into file.

editor($FILE_PATH, (oldData) => ({
  ...oldData,
  author: 'yrobot',
}));