Gatsby: Use the name "frontmatter" for JSX data exports

Created on 31 Jan 2018  路  4Comments  路  Source: gatsbyjs/gatsby

Currently, exports.data = { /* ... */ } is being used, which could also be written as export const data = { /* ... */ }, but the latter option can be inconvenient _(variable name clashes may occur)_ when a GraphQL query is also in place for the given JSX.

I would like to propose using export const frontmatter = { /* ... */ } in order to avoid confusion and improve consistence with markdown file handling.

Most helpful comment

In the past, I had more plans for this so I went with the more generic data. Those plans are pretty much now defunct though, and it seems to be only worthwhile to use this for frontmatter. I think, in an effort of discoverability and backward compatibility, we actually deprecate this package. Then we make a new package, gatsby-transformer-javascript-frontmatter, and make your proposed change. I think this will help others discover this package as I have noticed in the past that this package isn't quite obvious what it does at first glance. @KyleAMathews, are you amenable to this?

All 4 comments

/cc @jbolda

In the past, I had more plans for this so I went with the more generic data. Those plans are pretty much now defunct though, and it seems to be only worthwhile to use this for frontmatter. I think, in an effort of discoverability and backward compatibility, we actually deprecate this package. Then we make a new package, gatsby-transformer-javascript-frontmatter, and make your proposed change. I think this will help others discover this package as I have noticed in the past that this package isn't quite obvious what it does at first glance. @KyleAMathews, are you amenable to this?

@jbolda makes sense to me! Yeah, a more narrow package is easier to understand and discover.

It might be good to mention when and how to use this data. For example, I know that I can query the data with GraphQL, but how can I access it in the onCreatePage function in gatsby-node.js?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benstr picture benstr  路  3Comments

rossPatton picture rossPatton  路  3Comments

ghost picture ghost  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

brandonmp picture brandonmp  路  3Comments