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

Home Page:https://github.com/jonschlinkert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass Data in matter() Option

pxwee5 opened this issue · comments

Is there a way to pass global data or other kinds of data e.g. required() data in an object into the option field? That way we can just reference it like

---
images:
  small: {{image.mobile.src}}
  medium: {{image.tablet.src}}
  large: {{image.desktop.src}}
---

The object is supplied in another javascript code with

const image = require('hello.jpg?resize=500,100,1500')

This package (gray-matter) does not do anything with those values in the front matter. It just parses the front matter from the contents passed in and turns it into an object. This means your .data property will look like this:

{
  images: {
    small: '{{image.mobile.src}}',
    medium: '{{image.tablet.src}}',
    large: '{{image.desktop.src}}'
}

You can use something else, like expand to ... expand those values.