This plugin adds side-by-side previews, and quick links in the record sidebar to preview your webpages.
🚨 Important: This is not a drag & drop plugin! It requires a lambda function on your frontend website(s) in order to function. Read more in the following sections!
Once the plugin is installed you need to specify:
⚠️ For side-by-side previews to work, if your website implements a Content Security Policy frame-ancestors directive, you need to add https://plugins-cdn.datocms.com to your list of allowed sources, ie.:
Content-Security-Policy: frame-ancestors 'self' https://plugins-cdn.datocms.com;Each frontend must implement a CORS-ready JSON endpoint that, given a specific DatoCMS record, returns an array of preview link(s).
The plugin performs a POST request to the Previews webhook URL, passing a payload that includes the current environment, record and model:
{ "item": {…}, "itemType": {…}, "currentUser": {…}, "siteId": "123", "environmentId": "main", "locale": "en",}item: CMA entity of the current recorditemType: CMA entity of the model of the current recordcurrentUser: CMA entity of the collaborator, SSO user or account owner currently logged insiteId: the ID of the current DatoCMS projectenvironmentId: the current environment IDlocale: the locale currently active on the formThe endpoint is expected to return a 200 response, with the following JSON structure:
{ "previewLinks": [ { "label": "Published (en)", "url": "https://mysite.com/blog/my-article" }, { "label": "Draft (en)", "url": "https://mysite.com/api/preview/start?slug=/blog/my-article" } ]}The plugin will show all the preview links that are returned. If you want to make sure that a preview's URL is reloaded after each save, you can include an extra option (please be aware that because of cross-origin iframe issues, maintaining the scroll position between reloads will not be possible):
{ "label": "Draft (en)", "url": "https://mysite.com/api/preview/start?slug=/blog/my-article", "reloadPreviewOnRecordUpdate": { "delayInMs": 100 }}If you have built alternative endpoint implementations for other frameworks/SSGs, please open up a PR to this plugin and share it with the community!
We suggest you look at the code of our official Starter Kit:
app/api/preview-links/route.tsxapp/api/draft-mode/enable/route.tsx and app/api/draft-mode/disable/route.tsxThe preview link URLs also include a token query parameter that the plugin would send to the webhook receiver, like https://www.mywebsite.com/api/preview-links?token=some-secret-ish-string. The token is a string of your choice that just has to match in both the plugin settings and in your frontend's environment variables. While not encryption, this token is an easy way to limit access to your preview content.
We suggest you look at the code of our official Starter Kit:
server/api/draft-mode/enable.ts and server/api/draft-mode/disable.tsThe preview link URLs also include a token query parameter that the plugin would send to the webhook receiver, like https://www.mywebsite.com/api/preview-links?token=some-secret-ish-string. The token is a string of your choice that just has to match in both the plugin settings and in your frontend's environment variables. While not encryption, this token is an easy way to limit access to your preview content.
We suggest you look at the code of our official Starter Kit:
src/routes/api/preview-links/+server.tsroutes/api/draft-mode/enable/+server.ts and routes/api/draft-mode/disable/+server.tsThe preview link URLs also include a token query parameter that the plugin would send to the webhook receiver, like https://www.mywebsite.com/api/preview-links?token=some-secret-ish-string. The token is a string of your choice that just has to match in both the plugin settings and in your frontend's environment variables. While not encryption, this token is an easy way to limit access to your preview content.
We suggest you look at the code of our official Starter Kit:
src/pages/api/preview-links/index.tssrc/pages/api/draft-mode/enable/index.ts and src/pages/api/draft-mode/disable/index.tsThe preview link URLs also include a token query parameter that the plugin would send to the webhook receiver, like https://www.mywebsite.com/api/preview-links?token=some-secret-ish-string. The token is a string of your choice that just has to match in both the plugin settings and in your frontend's environment variables. While not encryption, this token is an easy way to limit access to your preview content.