From e640bdabc7d2210f3ab3e8b73baf0ed9762e1c9c Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 4 Feb 2026 11:19:06 +0530 Subject: [PATCH 1/4] done with live preview --- LIVE_PREVIEW_SETUP.md | 275 --------------------- app/applications/[slug]/changelog/page.tsx | 5 - app/applications/[slug]/page.tsx | 100 ++++++-- app/applications/page.tsx | 10 +- app/faqs/page.tsx | 10 +- app/page.tsx | 78 +++++- app/support/page.tsx | 9 +- components/LivePreviewProvider.tsx | 22 +- components/homepage/HeroSection.tsx | 13 +- components/homepage/ValuePropositions.tsx | 14 +- lib/contentstack.ts | 11 +- lib/livepreview.ts | 24 ++ lib/utils.ts | 11 - 13 files changed, 213 insertions(+), 369 deletions(-) delete mode 100644 LIVE_PREVIEW_SETUP.md create mode 100644 lib/livepreview.ts 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} -