Skip to content
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

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

Open
wouter-muller opened this issue Oct 6, 2021 · 4 comments
Assignees
Labels
area: configuration area: formats good first issue type: feature

Comments

@wouter-muller
Copy link

@wouter-muller wouter-muller commented Oct 6, 2021

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:

  • we use Netlify CMS to edit content that is stored in .yml files
  • directly editing content in .yml files in our IDE's

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!

@wouter-muller wouter-muller added the type: feature label Oct 6, 2021
@erezrokah
Copy link
Contributor

@erezrokah erezrokah commented Oct 6, 2021

Hi @wouter-muller, the conversion is done here:

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
Copy link

@elit-altum elit-altum commented Oct 8, 2021

@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
Copy link

@elit-altum elit-altum commented Oct 11, 2021

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

@erezrokah
Copy link
Contributor

@erezrokah erezrokah commented Oct 11, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: configuration area: formats good first issue type: feature
Projects
None yet
Development

No branches or pull requests

3 participants