diff --git a/LIVE_PREVIEW_SETUP.md b/LIVE_PREVIEW_SETUP.md deleted file mode 100644 index 33fc69d..0000000 --- a/LIVE_PREVIEW_SETUP.md +++ /dev/null @@ -1,275 +0,0 @@ -# Contentstack Live Preview Setup - -This document explains the live preview implementation for the DevDocs application using Contentstack's Live Preview functionality. - -## Overview - -Live Preview allows you to see content changes in real-time as you edit entries in the Contentstack CMS, without needing to publish or refresh the page manually. - -## Implementation Components - -### 1. Contentstack Stack Configuration - -The Stack is configured in [lib/contentstack.ts](lib/contentstack.ts) with live preview settings: - -```typescript -const Stack = contentstack.Stack({ - api_key: process.env.NEXT_PUBLIC_CONTENTSTACK_API_KEY!, - delivery_token: process.env.NEXT_PUBLIC_CONTENTSTACK_DELIVERY_TOKEN!, - environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT!, - live_preview: { - preview_token: process.env.PREVIEW_TOKEN!, - enable: true, - host: 'rest-preview.contentstack.com' // AWS NA region - }, -}); -``` - -### 2. Live Preview Provider Component - -Created [components/LivePreviewProvider.tsx](components/LivePreviewProvider.tsx) - a client-side component that initializes the Contentstack Live Preview Utils SDK. - -Key features: -- **Automatic initialization** on component mount -- **Environment-aware** - only enables in non-production environments -- **Edit button support** - displays edit buttons in the Live Preview portal -- **Debug mode** - enabled in development for troubleshooting -- **SSR mode** - configured for Next.js server-side rendering - -Configuration: -```typescript -ContentstackLivePreview.init({ - enable: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT !== 'production', - cleanCslpOnProduction: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT === 'production', - ssr: true, - stackDetails: { - apiKey: process.env.NEXT_PUBLIC_CONTENTSTACK_API_KEY!, - environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT!, - }, - clientUrlParams: { - host: 'app.contentstack.com', // AWS NA region - }, - editButton: { - enable: true, - exclude: ['outsideLivePreviewPortal'], - position: 'top-right', - }, -}); -``` - -### 3. Utility Function for Query Parameters - -Added `setLivePreviewQueryParams` function in [lib/utils.ts](lib/utils.ts) to handle live preview query parameters: - -```typescript -export function setLivePreviewQueryParams(queryParams: Record) { - if (queryParams?.live_preview) { - Stack.livePreviewQuery(queryParams as any); - } -} -``` - -This function: -- Checks if the request contains live preview parameters -- Injects the live preview hash and ContentType UID into the Stack instance -- Enables the delivery SDK to fetch preview content - -### 4. Root Layout Integration - -The `LivePreviewProvider` is included in [app/layout.tsx](app/layout.tsx) to initialize live preview globally: - -```typescript - - -
- {children} -