A Next.js application powered by Storyblok CMS for dynamic content management and delivery. Features draft mode, environment switching, and markdown rendering capabilities.
- 🚀 Built with Rect 19+, Next.js 15+, and App Router
- 📝 Storyblok CMS integration for dynamic content management
- 🔄 Draft mode for content preview switching
- 🌍 Environment switching (development/production)
- 📱 Dynamic slug-based routing for flexible page creation
- 🛠️ TypeScript support for type safety
- 📰 Markdown rendering capabilities
- 🍪 Cookie-based environment and draft mode management
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.envfile in the root directory:# Environment Configuration ENVIRONMENT=development # Storyblok Configuration STORYBLOK_API_URL=https://api.storyblok.com/v2/cdn STORYBLOK_ACCESS_TOKEN=your_access_token_here STORYBLOK_PREVIEW_ACCESS_TOKEN=your_preview_token_here # Draft Mode DRAFT_MODE=true
Replace
your_access_token_hereandyour_preview_token_herewith your actual Storyblok tokens from your Storyblok space settings. -
Run the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:3000 to see the application.
blok-by-blok/
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── globals.css # Global CSS styles
│ │ ├── layout.tsx # Root layout component
│ │ ├── page.tsx # Home page component
│ │ ├── favicon.ico # App favicon
│ │ ├── [slug]/ # Dynamic routing for Storyblok pages
│ │ │ └── page.tsx # Dynamic page component
│ │ └── api/ # Utility API routes
│ │ ├── clear-cookies/
│ │ │ └── route.ts # Clear environment/draft cookies
│ │ ├── set-draft-mode/
│ │ │ └── route.ts # Enable/disable draft mode
│ │ └── set-environment/
│ │ └── route.ts # Switch between environments
│ ├── components/ # Reusable UI components
│ │ ├── CookieNotice.tsx # Cookie consent notice
│ │ ├── EnvironmentToggle.tsx # Environment Controls
│ │ └── Markdown.tsx # Markdown content renderer
│ ├── types/
│ │ └── blokTypes.ts # Storyblok type definitions
│ └── utils/
│ └── storyblok.ts # Storyblok API utilities
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
-
Dynamic Routing (
[slug]):app/[slug]/page.tsxhandles all dynamic pages- Pages are created dynamically based on story slugs
- Supports nested routes and custom page structures from CMS
-
Storyblok API Integration:
src/utils/storyblok.tscontains API utilities and configurationsrc/types/blokTypes.tsdefines TypeScript types for content- Handles content fetching, draft mode, and environment switching
-
API Routes:
api/clear-cookies/route.ts- Clears environment and draft mode cookiesapi/set-draft-mode/route.ts- Toggles draft mode for content previewapi/set-environment/route.ts- Switches between development/production environments
-
Components:
CookieNotice.tsx- Manages cookie consent and notificationsEnvironmentToggle.tsx- UI for switching between environmentsMarkdown.tsx- Renders markdown content from Storyblok
- Draft Mode: Preview unpublished content using
/api/set-draft-mode - Environment Switching: Toggle between dev/prod content via
/api/set-environment - Dynamic Pages: All CMS pages accessible via
/[slug]route - Cookie Management: Environment and draft preferences stored in cookies
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint- Content is managed through Storyblok CMS
- Pages are automatically created based on story slugs
- Use draft mode to preview content before publishing
- Switch environments to test different content versions
For local development, you'll need to configure the following environment variables in your .env file:
ENVIRONMENT- Only needed forlocal development- Sets the current environment (development,previeworproduction)STORYBLOK_API_URL- Storyblok API endpoint (default:https://api.storyblok.com/v2/cdn)STORYBLOK_ACCESS_TOKEN- Your Storyblok access token for fetching publicpublishedcontentSTORYBLOK_PREVIEW_ACCESS_TOKEN- Your Storyblok token for preview draft and published content accessDRAFT_MODE- Enable/disable draft mode by default (trueorfalse)
- Log into your Storyblok account
- Navigate to your space settings
- Go to the "Access Tokens" section
- Copy the "Preview" token for
STORYBLOK_PREVIEW_ACCESS_TOKEN - Copy the "Public" token for
STORYBLOK_ACCESS_TOKEN
Note: this step is skipped for this demo as content was specifically set up for use in the demo
ENVIRONMENT=development
STORYBLOK_API_URL=https://api.storyblok.com/v2/cdn
STORYBLOK_ACCESS_TOKEN=your_public_token_here
STORYBLOK_PREVIEW_ACCESS_TOKEN=your_preview_token_here
DRAFT_MODE=trueNote: Never commit your .env file to version control. It's already included in .gitignore.
- Library: React 19+
- Framework: Next.js 15+ with App Router
- CMS: Storyblok for content management
- Language: TypeScript
- Styling: CSS Modules
- Content: Markdown rendering support
Deploy easily on Vercel or any platform that supports Next.js applications.
For detailed deployment instructions, see the Next.js deployment documentation.