decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.93k stars 3.04k forks source link

Field parameter to support adding quotes around field data #3505

Open jeremyzilar opened 4 years ago

jeremyzilar commented 4 years ago

Slightly related to https://github.com/netlify/netlify-cms/issues/3486

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

Background: I oversee Digital.gov, a site provides guidance around making better digital services for people in government. All of our websites are built using static site generators (Jekyll, Hugo), and use a mix of Federalist and GitHub to publish the pages.

Currently, most of the edits to our sites are made directly in the GitHub website from people not in our org, but people from around the government.

To make the process of editing fields easier, we are specifying that certain fields always have double quotes wrapped around them, regardless if there is a need for them or not.

For example, in the YML spec, the title field in the example below would not require it to be wrapped in quotes (title: "Introduction to Accessibility"), but because we have many editors and content designers going in to update the text fields, having double quotes around certain fields helps to ensure that the text they add will not break the build. This can be adding a colon, apostrophe, markdown formatting, etc... (title: "NEW: Introduction to Accessibility"). We have found that asking editors to remember to add quotes around an item if it has special chars is not something we coach them on in the workflow.

Here is an example of data fields and text fields 👀

slug: introduction-accessibility
date: 2019-12-04 8:00:00 -0500
title: "Introduction to Accessibility"
deck: ""
summary: "An introduction to accessibility, and why it matters."

Here's the full file

Describe the solution you'd like We are now making a switch to use Netlify CMS, and we'd like to be able to keep the ability to specify if a field should be automatically wrapped in double-quotes. This could be done by adding an optional parameter to the field you'd want wrapped in quotes (e.g. quotes: true)

Example:

      - label: "Agency Acronym"
        name: "agency"
        widget: "string"
        hint: "e.g. GSA"
        quotes: true
        required: false

When it renders, the field would get wrapped in quotes automatically. Ideally, the field in Netlify CMS would also look for the insertion of double quotes in the field and escape them.

title: "The \"Best\" Introduction to Accessibility"

Thank you for considering this 🌈✨

BasJan81 commented 4 years ago

I think quotes: true is a briljant idea.

Decisions, not Options

Every time you give a user an option, you are asking them to make a decision. When a user doesn’t care or understand the option this ultimately leads to frustration. As developers we sometimes feel that providing options for everything is a good thing, you can never have too many choices, right? Ultimately these choices end up being technical ones, choices that the average end user has no interest in. It’s our duty as developers to make smart design decisions and avoid putting the weight of technical choices on our end users.

dickreckard commented 2 years ago

Yes, +1 for quotes: true option.. Currently having an issue with a jekyll static site, where the liquid template interprets a field written as 12:12 as hours:minutes and mis-processes it. Of course it is not a netlify-cms issue, it is a Jekyll front-matter issue, implicitly interpreting a field without giving handles to modify that behaviour, but I imagine similar situations can appear in other YAML processes, and the quoting options seems a super-useful addition for helping with that.

manuelernestog commented 1 year ago

I'm having the same issue with Astro an YAML processes with time fields :/

pensivedog commented 1 year ago

+1 for quotes: true option.

martinjagodic commented 1 year ago

Since this seems to be a popular demand, I'm reopening the issue. Contributions welcome

DannieBGoode commented 1 year ago

same issue with Astro when since:

egxdigital commented 6 months ago

same issue with Astro when since:

  • Decap CMS writes them like this: publishDate: 2023-09-08T15:55:00.972Z
  • but Astro expects them like this: publishDate: "2023-09-08T15:55:00.972Z"

same issue with Next.js.

I also want to wrap Image fields in quote strings because they are saved as URIs for the Next.js build step to find them.

I have attempted several workarounds, none of which have worked:

Really wish there was a quotes: true for ALL DecapCMS fields