You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 adefaultValues
config setting with a map of values to use for missing frontmatter fields.The text was updated successfully, but these errors were encountered: