-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Docs: migrate Beta Features - Custom Formatters (#7056)
- Loading branch information
1 parent
f26ae53
commit 29ccb13
Showing
2 changed files
with
29 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}); | ||
``` |