From 29ccb135f715c4ebcbd395338545921d00b03402 Mon Sep 17 00:00:00 2001 From: Private Maker Date: Tue, 23 Jan 2024 10:35:38 +0100 Subject: [PATCH] Update Docs: migrate Beta Features - Custom Formatters (#7056) --- website/content/docs/beta-features.md | 26 -------------------- website/content/docs/custom-formatters.md | 29 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 website/content/docs/custom-formatters.md diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index 3e9af25d011a..6284b32e9b15 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -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), -}); -``` diff --git a/website/content/docs/custom-formatters.md b/website/content/docs/custom-formatters.md new file mode 100644 index 000000000000..f03dc4c5365b --- /dev/null +++ b/website/content/docs/custom-formatters.md @@ -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), +}); +```