Skip to content

Commit

Permalink
Update Docs: migrate Beta Features - Custom Formatters (#7056)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatemaker authored Jan 23, 2024
1 parent f26ae53 commit 29ccb13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
26 changes: 0 additions & 26 deletions website/content/docs/beta-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,3 @@ CMS.registerRemarkPlugin({ settings: { bullet: '-' } });
```
Note that `netlify-widget-markdown` currently uses `remark@10`, so you should check a plugin's compatibility first.

## Custom formatters

To manage content with other file formats than the built in ones, you can register a custom formatter:

```js
const JSON5 = require('json5');
CMS.registerCustomFormat('json5', 'json5', {
fromFile: text => JSON5.parse(text),
toFile: value => JSON5.stringify(value, null, 2),
});
```

Then include `format: json5` in your collection configuration. See the [Collection docs](https://www.netlifycms.org/docs/configuration-options/#collections) for more details.

You can also override the in-built formatters. For example, to change the YAML serialization method from [`yaml`](https://npmjs.com/package/yaml) to [`js-yaml`](https://npmjs.com/package/js-yaml):

```js
const jsYaml = require('js-yaml');
CMS.registerCustomFormat('yml', 'yml', {
fromFile: text => jsYaml.load(text),
toFile: value => jsYaml.dump(value),
});
```
29 changes: 29 additions & 0 deletions website/content/docs/custom-formatters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Custom formatters
weight: 60
group: Customization
---

To manage content with other file formats than the built in ones, you can register a custom formatter:

```js
const JSON5 = require('json5');

CMS.registerCustomFormat('json5', 'json5', {
fromFile: text => JSON5.parse(text),
toFile: value => JSON5.stringify(value, null, 2),
});
```

Then include `format: json5` in your collection configuration. See the [Collection docs](https://www.netlifycms.org/docs/configuration-options/#collections) for more details.

You can also override the in-built formatters. For example, to change the YAML serialization method from [`yaml`](https://npmjs.com/package/yaml) to [`js-yaml`](https://npmjs.com/package/js-yaml):

```js
const jsYaml = require('js-yaml');

CMS.registerCustomFormat('yml', 'yml', {
fromFile: text => jsYaml.load(text),
toFile: value => jsYaml.dump(value),
});
```

0 comments on commit 29ccb13

Please sign in to comment.