Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 8f54db1

Browse files
authored
docs: add netlify cms migration guide (#378)
1 parent c4733ca commit 8f54db1

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"name": "static-cms",
33
"private": true,
44
"scripts": {
5-
"build": "lerna run build",
6-
"build:demo": "lerna run build --scope=@staticcms/demo",
7-
"dev": "lerna run dev --scope=@staticcms/core",
8-
"demo": "lerna run dev --scope=@staticcms/demo",
9-
"docs": "lerna run dev --scope=docs",
5+
"build": "lerna run build --scope @staticcms/core --scope @staticcms/app",
6+
"build:demo": "lerna run build --scope @staticcms/demo",
7+
"dev": "lerna run dev --scope @staticcms/core",
8+
"demo": "lerna run dev --scope @staticcms/demo",
9+
"docs": "lerna run dev --scope docs",
1010
"format": "lerna run format",
1111
"lint": "lerna run lint",
1212
"prepare": "husky install",

packages/docs/content/docs/custom-widgets.mdx

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Register a custom widget.
2020

2121
```js
2222
// Using global window object
23-
CMS.registerWidget(name, control, [preview], [schema]);
23+
CMS.registerWidget(name, control, [preview], [{ schema }]);
2424

2525
// Using npm module import
2626
import CMS from '@staticcms/core';
27-
CMS.registerWidget(name, control, [preview], [schema]);
27+
CMS.registerWidget(name, control, [preview], [{ schema }]);
2828
```
2929

3030
### Params
@@ -159,7 +159,7 @@ Register widget takes an optional object of options. These options include:
159159
},
160160
};
161161
162-
CMS.registerWidget('categories', CategoriesControl, CategoriesPreview, options: { schema });
162+
CMS.registerWidget('categories', CategoriesControl, CategoriesPreview, { schema });
163163
</script>
164164
```
165165
@@ -203,6 +203,7 @@ collections: [
203203
}
204204
]
205205
```
206+
206207
</CodeTabs>
207208
208209
## Advanced field validation
@@ -260,3 +261,63 @@ const validator = () => {
260261
return this.existingPromise;
261262
};
262263
```
264+
265+
## Interacting With The Media Library
266+
267+
If you want to use the media library in your custom widget you will need to use the `useMediaInsert` and `useMediaAsset` hooks.
268+
269+
- `useMediaInsert` - Takes the current url to your media, details about your field (including a unique ID) and a callback method for when new media is uploaded.
270+
- `useMediaAsset` - Transforms your stored url into a usable url for displaying as a preview.
271+
272+
<CodeTabs>
273+
274+
```js
275+
import useMediaAsset from '@staticcms/core/lib/hooks/useMediaAsset';
276+
import useMediaInsert from '@staticcms/core/lib/hooks/useMediaInsert';
277+
278+
const FileControl = ({ collection, field, value, entry, onChange }) => {
279+
const handleOpenMediaLibrary = useMediaInsert(
280+
value,
281+
{ field, controlID },
282+
onChange,
283+
);
284+
285+
const assetSource = useMediaAsset(value, collection, field, entry);
286+
287+
return (
288+
<>
289+
<button type="button" onClick={handleOpenMediaLibrary}>Upload</button>
290+
<img role="presentation" src={assetSource} />
291+
</>
292+
);
293+
};
294+
```
295+
296+
```ts
297+
import useMediaAsset from '@staticcms/core/lib/hooks/useMediaAsset';
298+
import useMediaInsert from '@staticcms/core/lib/hooks/useMediaInsert';
299+
300+
import type { WidgetControlProps } from '@staticcms/core/interface';
301+
import type { FC } from 'react';
302+
303+
const FileControl: FC<WidgetControlProps<string, MyField>> =
304+
({ collection, field, value, entry, onChange }) => {
305+
306+
const handleOpenMediaLibrary = useMediaInsert(
307+
internalValue,
308+
{ field, controlID },
309+
onChange,
310+
);
311+
312+
const assetSource = useMediaAsset(value, collection, field, entry);
313+
314+
return (
315+
<>
316+
<button type="button" onClick={handleOpenMediaLibrary}>Upload</button>
317+
<img role="presentation" src={assetSource} />
318+
</>
319+
);
320+
};
321+
```
322+
323+
</CodeTabs>

packages/docs/content/docs/netlify-cms-migration-guide.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,34 @@ title: Netlify CMS Migration Guide
44
weight: 190
55
---
66

7-
Guide coming soon on how to migrate your site from Netlify CMS to Static CMS!
7+
Static CMS is a fork of Netlify CMS. Many changes have been made, some big, some small. If you are coming from Netlify CMS, here is the list items to watch out for while migrating.
8+
9+
## Changes
10+
- React `18.2.0` is now the minimum supported React version. If you are using Static CMS through a CDN, this comes bundled.
11+
- [Moment](https://momentjs.com/) has been dropped as the date library used. Instead we are now using [date-fns](https://date-fns.org/). Date formats in your configuration will need to be updated. See [format docs](https://date-fns.org/v2.29.3/docs/format).
12+
- CMS must be explicitly initiated now by calling `CMS.init()`
13+
- Passing a config to `CMS.init()` will now completely override `config.yml` (they are now exclusive), instead of being merged with `config.yml`
14+
- A [new markdown editor](/docs/widget-markdown) has been added. It comes with a new [shortcode](/docs/widget-markdown#shortcodes) system, old editor components no longer work.
15+
- Support in the List Widget for the `field` property has been dropped. A single field in the `fields` property [achieves the same behavior](/docs/widget-list).
16+
- Custom widget creation has changed slightly. React class components have been deprecated. Widgets should all be [functional components](https://reactjs.org/docs/components-and-props.html#function-and-class-components) now. There have also been changes to how custom widgets are registered and the properties passed to the controls and previews. See [custom widgets](/docs/custom-widgets) for full details.
17+
18+
## Deprecated and Removed Features
19+
- Dropped the following beta features from Netlify CMS.
20+
- GraphQL support for GitHub and GitLab
21+
- Remark plugins (new markdown editor has its own plugin system)
22+
- Dynamic Default Values
23+
- Custom Mount Element
24+
- Dropped support for AssetStore integration
25+
- Dropped support for Azure backend
26+
- All deprecated features were removed
27+
- `date` widget has been removed
28+
- `datetime` widget
29+
- `dateFormat` has been removed (Use `date_format` instead)
30+
- `timeFormat` has been removed (Use `time_foramt` instead)
31+
- Gitlab, Client-Side Implicit Grant has been removed
32+
- `createClass` is deprecated, [functional components](https://reactjs.org/docs/components-and-props.html#function-and-class-components) should be used instead. Basic react hooks are provided as globals now.
33+
- `getAsset` is deprecated, the new `useMediaAsset` hook should be used instead. See [Interacting With The Media Library](/docs/custom-widgets#interacting-with-the-media-library).
34+
35+
## Beta Features
36+
37+
All beta features from Netlify CMS that were kept, remain in beta and may not fully function in their current state. Please [submit an issue](https://github.com/StaticJsCMS/static-cms/issues) for any bugs you find.

packages/docs/src/components/docs/components/CodeTabs.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ const supportedLanguages: Record<string, CodeLanguage> = {
6060
grammar: Prism.languages.markdown,
6161
language: 'markdown',
6262
},
63+
'language-ts': {
64+
title: 'Typescript',
65+
grammar: Prism.languages.typescript,
66+
language: 'typescript',
67+
},
6368
};
6469

6570
interface TabData {

0 commit comments

Comments
 (0)