decaporg / decap-cms

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

Provide option to set number of spaces for indentation when Netlify CMS saves a .yml file #5870

Open wouter-muller opened 2 years ago

wouter-muller commented 2 years ago

I tried googling for this issue and found absolutely nothing, so i am opening up an issue.

The problem

We use two ways of editing the content of our website:

Because as a team we agreed on using 4 spaces for indentation (and prettier auto-formats this every time we save a file), and because Netlify CMS seems to use 2 spaces, everytime someone edits a .yml file in an editor the entire indentation of the file is set to 4, leading the entire file to be seen by git as "changed", which leads to quite unreadable git diffs.

Proposed solution:

Adding an optional key/value pair in the netlify.toml config file where you can override the default number of spaces. This would be a non-breaking change cause existing projects still would continue to use 2 spaces, and we can set it to 4 :)

Is this possible? What do you think about this idea?

Thanks in advance!

erezrokah commented 2 years ago

Hi @wouter-muller, the conversion is done here: https://github.com/netlify/netlify-cms/blob/bb7174d3b7cec3f0d45d6158043ae1b4d3182009/packages/netlify-cms-core/src/formats/yaml.ts#L56

and it seems it's possible https://eemeli.org/yaml/#tostring-options

On how to configure it, I'm not really sure. We should probably be consistent with exiting configuration structure: https://www.netlifycms.org/docs/configuration-options/#extension-and-format

This would make a good first contribution if someone wants to work on it

elit-altum commented 2 years ago

@erezrokah I'll take a shot at it!

How can we get the indent size provided by the user? In the toString() method we can use toString({ indent: <size> }) to set the indent.

elit-altum commented 2 years ago

@erezrokah Can you tell me how can I get the user specified indent size?

erezrokah commented 2 years ago

Hi @elit-altum, as a part of this issue we'll need to add this configuration item (we don't have it yet).

See my comment here. We probably need to add a format_indent_size option, or something similar.

We could also add an object:

format_options:
  indent_size: 4