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

Update Docs: migrate Beta Features - Custom Formatters #7056

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
});
```