Skip to content

Allow empty fields to be removed from frontmatter on update #2017

@richblend

Description

@richblend

Is your feature request related to a problem? Please describe.

When an optional field is left empty, it is not written to frontmatter at all when first published.
If an existing entry is updated, and a field that previously had a value is now empty, it is set as an empty string, instead of being removed completely.

I am seeing this behaviour on image fields. This is a problem for my build (using Gatsby JS), as when it infers its Graphql schema from the frontmatter data, it will incorrectly infer an image field as a string (since it detects the empty quotes), whereas I need it to be completely removed from frontmatter (in this case Graphql will not try to infer its schema from that particular entry).

Describe the solution you'd like

There is at least one existing issue requesting the opposite (#1988 - where updating empty values should default to empty string), so I think this could be an opt-in feature.

I'd like to be able to add an attribute to a widget field config, something like deleteWhenEmpty: true, that would completely strip out the frontmatter field if it is empty when published.

Describe alternatives you've considered

I have tried to deal with this on the Gatsby side, to remove nodes from Graphql that use empty quotes, but haven't had any luck so far.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions