From 10a7358806fa7e73f6e18c89101e92b2ba6f2dd5 Mon Sep 17 00:00:00 2001 From: Private Maker Date: Tue, 23 Jan 2024 12:44:03 +0100 Subject: [PATCH 1/4] Update Docs: migrate Beta Features - Registering CMS Events (#7058) --- website/content/docs/beta-features.md | 23 ------------------ website/content/docs/registering-events.md | 27 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 website/content/docs/registering-events.md diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index 6284b32e9b15..f44e853efeda 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -140,29 +140,6 @@ collections: The above config will transform the title field to uppercase and format the date field using `YYYY-MM-DD` format. Available transformations are `upper`, `lower`, `date('')`, `default('defaultValue')`, `ternary('valueForTrue','valueForFalse')` and `truncate()`/`truncate(, '')` -## Registering to CMS Events - -You can execute a function when a specific CMS event occurs. - -Example usage: - -```javascript -CMS.registerEventListener({ - name: 'prePublish', - handler: ({ author, entry }) => console.log(JSON.stringify({ author, data: entry.get('data') })), -}); -``` - -Supported events are `prePublish`, `postPublish`, `preUnpublish`, `postUnpublish`, `preSave` and `postSave`. The `preSave` hook can be used to modify the entry data like so: - -```javascript -CMS.registerEventListener({ - name: 'preSave', - handler: ({ entry }) => { - return entry.get('data').set('title', 'new title'); - }, -}); -``` ## Dynamic Default Values diff --git a/website/content/docs/registering-events.md b/website/content/docs/registering-events.md new file mode 100644 index 000000000000..34556b49be7c --- /dev/null +++ b/website/content/docs/registering-events.md @@ -0,0 +1,27 @@ +--- +title: Registering to CMS Events +weight: 80 +group: Customization +--- + +You can execute a function when a specific CMS event occurs. + +Example usage: + +```javascript +CMS.registerEventListener({ + name: 'prePublish', + handler: ({ author, entry }) => console.log(JSON.stringify({ author, data: entry.get('data') })), +}); +``` + +Supported events are `prePublish`, `postPublish`, `preUnpublish`, `postUnpublish`, `preSave` and `postSave`. The `preSave` hook can be used to modify the entry data like so: + +```javascript +CMS.registerEventListener({ + name: 'preSave', + handler: ({ entry }) => { + return entry.get('data').set('title', 'new title'); + }, +}); +``` From a3939e0c20850aadc71e376e4578fd1f996a5fdb Mon Sep 17 00:00:00 2001 From: Private Maker Date: Tue, 23 Jan 2024 12:46:37 +0100 Subject: [PATCH 2/4] Update Docs: migrate Beta Features - Dynamic Default Values (#7060) --- website/content/docs/beta-features.md | 34 ----------------- .../content/docs/dynamic-default-values.md | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 website/content/docs/dynamic-default-values.md diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index f44e853efeda..51b06dbb32c4 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -141,40 +141,6 @@ The above config will transform the title field to uppercase and format the date Available transformations are `upper`, `lower`, `date('')`, `default('defaultValue')`, `ternary('valueForTrue','valueForFalse')` and `truncate()`/`truncate(, '')` -## Dynamic Default Values - -When linking to `/admin/#/collections/posts/new` you can pass URL parameters to pre-populate an entry. - -For example given the configuration: - -```yaml -collections: - - name: posts - label: Posts - folder: content/posts - create: true - fields: - - label: Title - name: title - widget: string - - label: Object - name: object - widget: object - fields: - - label: Title - name: title - widget: string - - label: body - name: body - widget: markdown -``` - -clicking the following link: `/#/collections/posts/new?title=first&object.title=second&body=%23%20content` - -will open the editor for a new post with the `title` field populated with `first`, the nested `object.title` field -with `second` and the markdown `body` field with `# content`. - -**Note:** URL Encoding might be required for certain values (e.g. in the previous example the value for `body` is URL encoded). ## Remark plugins diff --git a/website/content/docs/dynamic-default-values.md b/website/content/docs/dynamic-default-values.md new file mode 100644 index 000000000000..775886150ca8 --- /dev/null +++ b/website/content/docs/dynamic-default-values.md @@ -0,0 +1,38 @@ +--- +title: Dynamic Default Values +group: Fields +weight: 30 +--- + +When linking to `/admin/#/collections/posts/new` you can pass URL parameters to pre-populate an entry. + +For example given the configuration: + +```yaml +collections: + - name: posts + label: Posts + folder: content/posts + create: true + fields: + - label: Title + name: title + widget: string + - label: Object + name: object + widget: object + fields: + - label: Title + name: title + widget: string + - label: body + name: body + widget: markdown +``` + +clicking the following link: `/#/collections/posts/new?title=first&object.title=second&body=%23%20content` + +will open the editor for a new post with the `title` field populated with `first`, the nested `object.title` field +with `second` and the markdown `body` field with `# content`. + +**Note:** URL Encoding might be required for certain values (e.g. in the previous example the value for `body` is URL encoded). From c21b30db4fef06f3ac0daec23b583d896cffe5ab Mon Sep 17 00:00:00 2001 From: Private Maker Date: Tue, 23 Jan 2024 14:09:40 +0100 Subject: [PATCH 3/4] Update Docs: migrate Beta Features - Image Size Limit (#7062) * Update Docs: migrate Beta Features - Image Size Limit * Docs: add media limit to File widget, trim example text --- website/content/docs/beta-features.md | 15 --------------- website/content/docs/widgets/file.md | 12 ++++++++++++ website/content/docs/widgets/image.md | 14 +++++++++++++- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index 51b06dbb32c4..85f20eeef3b6 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -103,21 +103,6 @@ You can now provide your own element for Decap CMS to mount in by setting the ta -## Image widget file size limit - -You can set a limit to as what the maximum file size of a file is that users can upload directly into a image field. - -Example config: - -```yaml -- label: 'Featured Image' - name: 'thumbnail' - widget: 'image' - default: '/uploads/chocolate-dogecoin.jpg' - media_library: - config: - max_file_size: 512000 # in bytes, only for default media library -``` ## Summary string template transformations diff --git a/website/content/docs/widgets/file.md b/website/content/docs/widgets/file.md index 3df31c7de762..4987407064b5 100644 --- a/website/content/docs/widgets/file.md +++ b/website/content/docs/widgets/file.md @@ -29,3 +29,15 @@ The file widget allows editors to upload a file or select an existing one from t config: multiple: true ``` + +### File Size Limit + +You can set a limit to as what the maximum file size of a file is that users can upload directly into a file field. + +**Example** + +```yaml + media_library: + config: + max_file_size: 1024000 # in bytes, only for default media library +``` diff --git a/website/content/docs/widgets/image.md b/website/content/docs/widgets/image.md index 5236c0b2ed13..5151412061e5 100644 --- a/website/content/docs/widgets/image.md +++ b/website/content/docs/widgets/image.md @@ -28,4 +28,16 @@ The image widget allows editors to upload an image or select an existing one fro media_library: config: multiple: true -``` \ No newline at end of file +``` + +### Image Size Limit + +You can set a limit to as what the maximum file size of a file is that users can upload directly into a image field. + +**Example** + +```yaml + media_library: + config: + max_file_size: 512000 # in bytes, only for default media library +``` From 4411cc0b12a4e3815df5eca767e0ac5b07611ed0 Mon Sep 17 00:00:00 2001 From: Private Maker Date: Tue, 23 Jan 2024 14:10:53 +0100 Subject: [PATCH 4/4] Update Docs: migrate Beta Features - Custom Mount Element (#7059) * Update Docs: migrate Beta Features - Custom Mount Element * Update Docs: add more details to Custom Mounting --------- Co-authored-by: Martin Jagodic --- website/content/docs/beta-features.md | 5 ----- website/content/docs/custom-mounting.md | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 website/content/docs/custom-mounting.md diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index 85f20eeef3b6..b54c1f6258ed 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -93,11 +93,6 @@ sections: - images/image06.png ``` -## Custom Mount Element - -Decap CMS always creates its own DOM element for mounting the application, which means it always takes over the entire page, and is generally inflexible if you're trying to do something creative, like injecting it into a shared context. - -You can now provide your own element for Decap CMS to mount in by setting the target element's ID as `nc-root`. If Decap CMS finds an element with this ID during initialization, it will mount within that element instead of creating its own. diff --git a/website/content/docs/custom-mounting.md b/website/content/docs/custom-mounting.md new file mode 100644 index 000000000000..fd8c5c5552ad --- /dev/null +++ b/website/content/docs/custom-mounting.md @@ -0,0 +1,17 @@ +--- +title: Custom Mount Element +weight: 90 +group: Customization +--- + +Decap CMS always creates its own DOM element for mounting the application, which means it always takes over the entire page, and is generally inflexible if you're trying to do something creative, like injecting it into a shared context. + +You can now provide your own element for Decap CMS to mount in by setting the target element's ID as `id="nc-root"`. If Decap CMS finds an element with this ID during initialization, it will mount within that element instead of creating its own. + +This is useful if you want to create a wrapper around the CMS, like a custom header, footer, or sidebar. + +**Example** + +Adding the following div to `admin/index.html` will cause the CMS to load within it: + +