|
| 1 | +--- |
| 2 | +title: Content Source Map plugin |
| 3 | +description: Use the Content Source Map plugin with Vercel Visual Editing to enhance the content edition experience. |
| 4 | +sidebar_label: Content Source Map |
| 5 | +displayed_sidebar: devDocsSidebar |
| 6 | +--- |
| 7 | + |
| 8 | +import CSMPrereq from '/docs/snippets/content-source-map-requirements.md' |
| 9 | + |
| 10 | +# Content Source Map plugin <EnterpriseBadge /> |
| 11 | + |
| 12 | +<CSMPrereq /> |
| 13 | + |
| 14 | +The Content Source Map plugin adds content source maps support to a Strapi project. |
| 15 | + |
| 16 | +Content source maps are invisible values that include a link back to the field that generated the content. When combined with [Vercel's Visual Editing](https://vercel.com/docs/workflow-collaboration/visual-editing) feature, content source maps allow navigating directly from the front-end website of a Strapi-based project to the source of a field in Strapi's admin panel, making editing content more intuitive. |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +To add the Content Source Map plugin to your Strapi project, run the following command in the terminal: |
| 21 | + |
| 22 | +<Tabs groupId="yarn-npm"> |
| 23 | + |
| 24 | +<TabItem value="yarn" label="yarn"> |
| 25 | + |
| 26 | +```bash |
| 27 | +yarn add @strapi/plugin-content-source-map |
| 28 | +``` |
| 29 | + |
| 30 | +</TabItem> |
| 31 | + |
| 32 | +<TabItem value="npm" label="npm"> |
| 33 | + |
| 34 | +```bash |
| 35 | +npm install @strapi/plugin-content-source-map |
| 36 | +``` |
| 37 | + |
| 38 | +</TabItem> |
| 39 | + |
| 40 | +</Tabs> |
| 41 | + |
| 42 | +## Configuration |
| 43 | + |
| 44 | +Once installed, the Content Source Map plugin should be enabled and configured in your project by adding relevant parameters to the [plugins configuration file](/dev-docs/configurations/plugins): |
| 45 | + |
| 46 | +| Name | Description | Default | |
| 47 | +|----------------|-----------------------------------------------------------------------|-------------| |
| 48 | +| `contentTypes` | Array of content type uids to enable content source map for. | `[]` | |
| 49 | +| `origin` | Origin defined in the source map and used to display the edit button. | `strapi.io` | |
| 50 | +| `baseHref` | Base URL of your Strapi admin panel. | Generated based on the [`server.url` configuration value](/dev-docs/configurations/server) | |
| 51 | + |
| 52 | +<Tabs groupId="js-ts"> |
| 53 | + |
| 54 | +<TabItem value="js" label="JavaScript"> |
| 55 | + |
| 56 | +```jsx title="./config/plugins.js" |
| 57 | + |
| 58 | +module.exports = () => ({ |
| 59 | + 'content-source-map': { |
| 60 | + enabled: true, |
| 61 | + config: { |
| 62 | + contentTypes: ['api::article.article', 'api::restaurant.restaurant'], |
| 63 | + origin: 'strapi.io', |
| 64 | + baseHref: 'https://my.strapi-admin.com', |
| 65 | + }, |
| 66 | + }, |
| 67 | +}); |
| 68 | +``` |
| 69 | + |
| 70 | +</TabItem> |
| 71 | + |
| 72 | +<TabItem value="ts" label="TypeScript"> |
| 73 | + |
| 74 | +```jsx title="./config/plugins.ts" |
| 75 | + |
| 76 | +export default () => ({ |
| 77 | + 'content-source-map': { |
| 78 | + enabled: true, |
| 79 | + config: { |
| 80 | + contentTypes: ['api::article.article', 'api::restaurant.restaurant'], |
| 81 | + origin: 'strapi.io', |
| 82 | + baseHref: 'https://my.strapi-admin.com', |
| 83 | + }, |
| 84 | + }, |
| 85 | +}); |
| 86 | +``` |
| 87 | + |
| 88 | +</TabItem> |
| 89 | + |
| 90 | +</Tabs> |
| 91 | + |
| 92 | +## Usage |
| 93 | + |
| 94 | +The Content Source Map plugin adds content source map support to the following API endpoints: |
| 95 | + |
| 96 | +- `GET /api/:contentType` to list a content type entries |
| 97 | +- `GET /api/:contentType/:id` to retrieve a content type entry by id |
| 98 | + |
| 99 | +To include source map data in the response, you will have to add the `encodeSourceMaps=true` query parameter to your [REST API](/dev-docs/api/rest) calls. Vercel will automatically detect Content Source Maps on the deployed website. |
| 100 | + |
| 101 | +:::caution |
| 102 | +This will have performance impacts so you should use this only in draft mode or when doing previews. |
| 103 | +::: |
| 104 | + |
| 105 | +:::tip |
| 106 | +To see the Content Source Map plugin and Vercel Live Editing in action, refer to the [User Guide](/user-docs/content-manager/writing-content#editing-fields-from-a-front-end-website-). |
| 107 | +::: |
0 commit comments