Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-transformer-remark] Support Frontmatter Field Default Values #5392

Closed
Undistraction opened this issue May 12, 2018 · 3 comments
Closed
Labels
help wanted Issue with a clear description that the community can help with.

Comments

@Undistraction
Copy link
Contributor

At present there is no way of setting default values for markdown frontmatter fields.

For example, imagine each Article node has a frontmatter field called 'category' which may or may not be present.

At the moment there is no mechanism to populate this field with a default value – for example 'Uncategorised'. Because nodes are immutable this field cannot be populated in gatsby-node.js, so the only option is to add a 'category' to the node's 'fields' which feels a little unnecessary.

I suggest that gatsby-transformer-remark should accept a defaultValues config setting with a map of values to use for missing frontmatter fields.

@m-allanson m-allanson added the help wanted Issue with a clear description that the community can help with. label May 14, 2018
@m-allanson
Copy link
Contributor

This sounds like a useful feature 👍

@Undistraction
Copy link
Contributor Author

I encountered another place where this would be helpful - at present, if a field is not defined in the frontmatter of an (e.g. Article), Gatsby will throw an error when a query tries to access that field. In many cases this error is useful , but in cases where a frontmatter field is optional, it is possible for all Articles not to have that field, but the query for that field to be valid (it should just return nothing). This then (unnecessarily) puts the onus on the author to ensure default values are present to prevent an error during build. If we could supply default values as part of configuration, this would provide a way of flagging a field as optional, removing potential for these errors to occur.

@KyleAMathews
Copy link
Contributor

Closing per my comment in #5495 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with.
Projects
None yet
Development

No branches or pull requests

4 participants