Skip to content

Commit 1f259d2

Browse files
Merge pull request #157 from contentstack/development
DX Release 21-04-2025
2 parents 53bb340 + da77e0e commit 1f259d2

File tree

5 files changed

+552
-824
lines changed

5 files changed

+552
-824
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [1.3.20](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.20) (2025-02-24)
44
- Fix: Added data-mtec as allowed attribute
5+
- Fix: customRenderOption for entry-embedded-as-link nodes
56

67
## [1.3.19](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.19) (2025-02-24)
78
- Fix: Added fix for html injection in keys and values of attributes

README.md

Lines changed: 93 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ To get started with JavaScript, you will need the following:
1010
- Node.js 10 or later
1111

1212
## SDK Installation and Setup
13-
> Note: If you are using JavaScript Contentstack SDK, you don’t need to run the command as ‘@contentstack/utils’ is already imported in the SDK.
1413

1514
Use the following command to install Contentstack JavaScript Utils SDK:
1615
```sh
@@ -87,104 +86,119 @@ Contentstack Utils SDK lets you interact with the Content Delivery APIs and retr
8786
### Fetch Embedded Item(s) from a Single Entry
8887
#### Render HTML RTE Embedded object
8988
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use the `includeEmbeddedItems` and `Contentstack.Utils.render` functions as shown below:
90-
```js
91-
import * as Contentstack from 'contentstack'
92-
const stack = Contentstack.Stack({
93-
api_key: '<API_KEY>',
94-
delivery_token: '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>',
95-
environment: '<ENVIRONMENT>'})
96-
97-
stack.ContentType('<CONTENT_TYPE_UID>')
98-
.Entry('<ENTRY_UID>')
99-
.toJSON()
100-
.includeEmbeddedItems() // include embedded items
101-
.fetch()
102-
.then(entry => {
103-
Contentstack.Utils.render({ entry, renderOption })
104-
})
89+
```ts
90+
import contentstack, { StackConfig } from '@contentstack/delivery-sdk';
91+
92+
const params: StackConfig = {
93+
apiKey: <API_KEY>,
94+
deliveryToken: <DELIVERY_TOKEN>,
95+
environment: <ENVIRONMENT>,
96+
}
97+
const Stack = contentstack.stack(params);
98+
99+
const result = await Stack
100+
.contentType('<CONTENT_TYPE_UID>')
101+
.entry('<ENTRY_UID>')
102+
.includeEmbeddedItems()
103+
.fetch<BlogPostEntry>();
104+
105+
Contentstack.Utils.render({
106+
entry: result,
107+
renderOption
108+
})
105109
```
106110
If you have multiple RTE fields in an entry and want to fetch the embedded items from a particular RTE field, you need to provide a path of those RTE fields.
107111

108112
Refer to the example code below:
109-
```js
113+
```ts
110114
//code to render embedded item from an RTE field and from another RTE field nested within a group field
111-
Contentstack.Utils.render({ entry, path: ["rte_fieldUid", "group.rteFieldUID"], renderOption })
115+
Contentstack.Utils.render({
116+
entry: result,
117+
path: ["rte_fieldUid", "group.rteFieldUID"],
118+
renderOption
119+
})
112120
```
113121

114122
#### Render Supercharged RTE contents
115123
To get a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack.Utils.jsonToHTML` function as shown below:
116-
```js
117-
import * as Contentstack from 'contentstack'
118-
const stack = Contentstack.Stack({
119-
api_key: '<API_KEY>',
120-
delivery_token: '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>',
121-
environment: '<ENVIRONMENT>'})
122-
123-
stack.ContentType('<CONTENT_TYPE_UID>')
124-
.Entry('<ENTRY_UID>')
125-
.toJSON()
126-
.fetch()
127-
.then(entry => {
128-
Contentstack.Utils.jsonToHTML({
129-
entry,
130-
path: ["rte_fieldUid", "group.rteFieldUID"],
131-
renderOption
132-
})
133-
})
124+
```ts
125+
import contentstack, { StackConfig } from '@contentstack/delivery-sdk';
126+
127+
const params: StackConfig = {
128+
apiKey: <API_KEY>,
129+
deliveryToken: <DELIVERY_TOKEN>,
130+
environment: <ENVIRONMENT>,
131+
}
132+
const Stack = contentstack.stack(params);
133+
134+
const result = await Stack
135+
.contentType('<CONTENT_TYPE_UID>')
136+
.entry('<ENTRY_UID>')
137+
.includeEmbeddedItems()
138+
.fetch<BlogPostEntry>();
139+
140+
Contentstack.Utils.jsonToHTML({
141+
entry: result,
142+
paths: ["rte_fieldUid", "group.rteFieldUID"],
143+
renderOption
144+
})
134145
```
135146
> Node: Supercharged RTE also supports Embedded items to get all embedded items while fetching entry use `includeEmbeddedItems` function.
136147
137148
### Fetch Embedded Item(s) from Multiple Entries
138149
#### Render HTML RTE Embedded object
139150

140151
To get embedded items from multiple entries, you need to provide the content type UID. You can also use the path variable in case the entries have multiple RTE fields.
141-
```js
142-
import Contentstack from 'contentstack'
143-
const stack = Contentstack.Stack({
144-
api_key: '<API_KEY>',
145-
delivery_token: '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>',
146-
environment: '<ENVIRONMENT>'})
147-
148-
stack.ContentType('<CONTENT_TYPE_UID>')
149-
.Query()
150-
.toJSON()
151-
.where('title', '<entry_title_to_search>')
152-
.includeEmbeddedItems() // include embedded items
153-
.find()
154-
.then(result => {
155-
result.forEach(entry => {
156-
Contentstack.Utils.render({
157-
entry,
158-
path: ['rte', 'group.rteFieldUID'],
159-
renderOption
160-
})
161-
})
162-
})
152+
```ts
153+
import contentstack, { StackConfig } from '@contentstack/delivery-sdk'
154+
155+
const params: StackConfig = {
156+
apiKey: <API_KEY>,
157+
deliveryToken: <DELIVERY_TOKEN>,
158+
environment: <ENVIRONMENT>,
159+
}
160+
const Stack = contentstack.stack(params);
161+
162+
const result = await Stack
163+
.contentType('<CONTENT_TYPE_UID>')
164+
.entry()
165+
.includeEmbeddedItems()
166+
.find<BlogPostEntry>();
167+
168+
result.entries.forEach(entry => {
169+
Contentstack.Utils.render({
170+
entry,
171+
paths: ["rte_fieldUid", "group.rteFieldUID"],
172+
renderOption
173+
})
174+
})
163175
```
164176

165177
#### Render Supercharged RTE contents
166178
To get a multiple entries, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack.Utils.jsonToHTML` function as shown below:
167-
```js
168-
import * as Contentstack from 'contentstack'
169-
const stack = Contentstack.Stack({
170-
api_key: '<API_KEY>',
171-
delivery_token: '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>',
172-
environment: '<ENVIRONMENT>'})
173-
174-
stack.ContentType('<CONTENT_TYPE_UID>')
175-
.Query()
176-
.toJSON()
177-
.where('title', '<entry_title_to_search>')
178-
.find()
179-
.then(result => {
180-
result.forEach(entry => {
181-
Contentstack.Utils.jsonToHTML({
182-
entry,
183-
path: ["rte_fieldUid", "group.rteFieldUID"],
184-
renderOption
185-
})
186-
})
187-
})
179+
```ts
180+
import contentstack, { StackConfig } from '@contentstack/delivery-sdk';
181+
182+
const params: StackConfig = {
183+
apiKey: <API_KEY>,
184+
deliveryToken: <DELIVERY_TOKEN>,
185+
environment: <ENVIRONMENT>,
186+
}
187+
const Stack = contentstack.stack(params);
188+
189+
const result = await Stack
190+
.contentType('<CONTENT_TYPE_UID>')
191+
.entry()
192+
.includeEmbeddedItems()
193+
.find<BlogPostEntry>();
194+
195+
result.entries.forEach(entry => {
196+
Contentstack.Utils.jsonToHTML({
197+
entry,
198+
paths: ["rte_fieldUid", "group.rteFieldUID"],
199+
renderOption
200+
})
201+
})
188202
```
189203

190204
> Node: Supercharged RTE also supports Embedded items to get all embedded items while fetching entry use `includeEmbeddedItems` function.

0 commit comments

Comments
 (0)