Skip to content

Commit a9cc747

Browse files
authored
docs: add local api instructions for vercel content link (#12385)
The docs for Vercel Content Link only included instructions on how to enable content source maps for the REST API. The Local API, although supported, was lacking documentation.
1 parent fd67d46 commit a9cc747

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

docs/integrations/vercel-content-link.mdx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,50 @@ const config = buildConfig({
6363
export default config
6464
```
6565

66-
Now in your Next.js app, include the `?encodeSourceMaps=true` parameter in any of your API requests. For performance reasons, this should only be done when in draft mode or on preview deployments.
66+
## Enabling Content Source Maps
67+
68+
Now in your Next.js app, you need to add the `encodeSourceMaps` query parameter to your API requests. This will tell Payload to include the Content Source Maps in the API response.
69+
70+
<Banner type="warning">
71+
**Note:** For performance reasons, this should only be done when in draft mode
72+
or on preview deployments.
73+
</Banner>
74+
75+
#### REST API
76+
77+
If you're using the REST API, include the `?encodeSourceMaps=true` search parameter.
6778

6879
```ts
6980
if (isDraftMode || process.env.VERCEL_ENV === 'preview') {
7081
const res = await fetch(
71-
`${process.env.NEXT_PUBLIC_PAYLOAD_CMS_URL}/api/pages?where[slug][equals]=${slug}&encodeSourceMaps=true`,
82+
`${process.env.NEXT_PUBLIC_PAYLOAD_CMS_URL}/api/pages?encodeSourceMaps=true&where[slug][equals]=${slug}`,
7283
)
7384
}
7485
```
7586

87+
#### Local API
88+
89+
If you're using the Local API, include the `encodeSourceMaps` via the `context` property.
90+
91+
```ts
92+
if (isDraftMode || process.env.VERCEL_ENV === 'preview') {
93+
const res = await payload.find({
94+
collection: 'pages',
95+
where: {
96+
slug: {
97+
equals: slug,
98+
},
99+
},
100+
context: {
101+
encodeSourceMaps: true,
102+
},
103+
})
104+
}
105+
```
106+
76107
And that's it! You are now ready to enter Edit Mode and begin visually editing your content.
77108

78-
#### Edit Mode
109+
## Edit Mode
79110

80111
To see Content Link on your site, you first need to visit any preview deployment on Vercel and login using the Vercel Toolbar. When Content Source Maps are detected on the page, a pencil icon will appear in the toolbar. Clicking this icon will enable Edit Mode, highlighting all editable fields on the page in blue.
81112

@@ -94,7 +125,9 @@ const { cleaned, encoded } = vercelStegaSplit(text)
94125

95126
### Blocks and array fields
96127

97-
All `blocks` and `array` fields by definition do not have plain text strings to encode. For this reason, they are given an additional `_encodedSourceMap` property, which you can use to enable Content Link on entire _sections_ of your site. You can then specify the editing container by adding the `data-vercel-edit-target` HTML attribute to any top-level element of your block.
128+
All `blocks` and `array` fields by definition do not have plain text strings to encode. For this reason, they are automatically given an additional `_encodedSourceMap` property, which you can use to enable Content Link on entire _sections_ of your site.
129+
130+
You can then specify the editing container by adding the `data-vercel-edit-target` HTML attribute to any top-level element of your block.
98131

99132
```ts
100133
<div data-vercel-edit-target>

0 commit comments

Comments
 (0)