decaporg / decaporg/decap-cms

Remove leading/trailing whitespace in frontmatter when submitting

Open
#7,398 0 comments 3 reactions 0 assignees View on GitHub
type: feature
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

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

I’m a developer at [Filecoin Foundation](https://github.com/FilecoinFoundationWeb) and review content PRs coming from Decap CMS.

I’ve noticed that some Markdown entries have leading and trailing spaces in the frontmatter. I don't think our content team does this intentionally, but either way, there should be a way to **automatically clean the frontmatter strings before submission to GitHub**. The result would be the equivalent of calling [.trim()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) on the strings.

```md
---
title: " Fresh From FF: February, 2025 " # Should not happen
created-on: 2025-02-03T15:32:00.000Z
updated-on: 2025-02-03T15:32:00.000Z
published-on: 2025-02-03T15:32:00.000Z
category: reports
description: Check out the latest updates about what Filecoin Foundation has been up to.
```

### **Describe the solution you'd like**

I believe this should be handled automatically. I can’t think of a scenario where leading or trailing spaces in a string are intentional or useful for content authors.

If doing it automatically isn’t an option, there should at least be a option in `config.yml`, such as:

```yml
local_backend: true
site_url: https://fil.org
display_url: https://fil.org

# ...

trim_whitespace: true
```

### **Describe alternatives you've considered**

We tried registering a [pre-save hook](https://decapcms.org/docs/registering-events/) to do this, but handling all edge cases—especially with deeply nested content—proved to be too tricky.

We also tried using Prettier to clean the content, but it doesn’t remove whitespace from strings enclosed in quotation marks.

### **Additional context**

Let me know if I can help!

Thank you 🙂

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.