-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Delete front matter values completely if optional string widget left empty in CMS #995
Comments
@TristianK3604 What field were you wondering this about? Most fields seem to be removed automatically for me. |
@tech4him1 It's for all the front matter fields, the one I specifically would like Netlify CMS to remove is "Documentation URL". |
It looks like this is only for |
Unfortunately, fixing this would represent a breaking change, since templates may be relying on an ever-present field with an empty string when empty. @TristianK3604 honestly, I'm tempted to say removing vs. not removing is a horse a piece. The inconsistency isn't good if other widget fields are removed when empty, true, but can't you just check for the empty string value for your use case? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue best explains #2848, #2007, #1449, and #2017 - closing those in favor of this. When a widget returns a falsey value that should not be persisted (often an empty string), the widget should instead pass Because many Gatsby sites are likely depending on the current behavior, we should introduce this as off-by-default until 3.0, but enough users have brought up this issue that it seems worth addressing sooner rather than later. |
Here's another use case and why this is relevant for me: By default Jekyll will get the title: 'Oh hai there' # URL would be: /blog/oh-hai-there/ But that can be overwritten with the title: 'Oh hai there'
slug: 'hai' # URL is now /blog/hai/ What's sad is that if you change your mind and remove the value in title: 'Oh hai there'
slug: '' # URL is now ruined /blog// |
In case anyone's looking for how to deal with this for frontmatter images Gatsby. You can work around this for now by explicitly typing the field in your GraphQL schema with In exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
// Explicitly define the Markdown frontmatter object
// This way those will always be defined as file even if CMS leaves a blank string
// This way the queries will return `null` even when a blank string is left
createTypes(`
{ ... }
type MarkdownRemark implements Node {
frontmatter: Frontmatter
fields: Fields
}
type Frontmatter {
{ ... }
imagePath: File @fileByRelativePath // this is the important bit
{ ... }
}
{ ... }
`)
} |
It also affect the image widget. Removing an image will leave an empty string. |
I've looked all over the place until I found your solution. Your solution is really elegant, thanks for sharing. I'm just wondering how did you find out that |
- Do you want to request a feature or report a bug?
Request a feature
- What is the current behavior?
When emptying a field in the CMS, then re-publishing, it leaves the
example:
there- If the current behavior is a bug, please provide the steps to reproduce.
- What is the expected behavior?
Delete it completely
- Please mention your CMS, node.js, and operating system version.
Netlify CMS 1.0, Node.js 6.12.3
- Please link or paste your
config.yml
below if applicable.The text was updated successfully, but these errors were encountered: