This repository is a Next.js Storyblok starter template.
To use this project you have to have a Storyblok account. If you don't have one yet you can register at Storyblok, it's free.
Read the Next.js 13 tutorial about connecting Storyblok and Next.js
Create a new repository from this template by clicking the Use this template button.
yarn # or npm install
Create a new empty space and copy the Preview Token. Create your .env.local
from .env.example
:
mv .env.example .env.local
Add the token from Storyblok and a password/any string for the preview-mode (and the webhook):
STORYBLOK_TOKEN=<your-new-token>
SECRET=<your-token-or-password>
Set the preview domain in Storyblok to http://localhost:3000/
# to run in developer mode
yarn dev # or npm run dev
# to build your project
yarn build # or npm run build
First, make sure you have the Storyblok CLI installed and set up with your account. Next, replace SPACE_ID
in package.json
with your space ID e.g. 123456
.
# get current component definition
yarn pull-components
# generate boilerplate components
yarn generate-components
Whenever your component definitions have changes, you can update your types:
# generate types from component definition
yarn generate-sb-types
To enable preview mode you have to add two preview URLs in Storyblok:
Preview
https://<my-url>/api/draft?secret=<your-preview-password-or-token>&slug=
Exit Preview
https://<my-url>/api/exit-draft?slug=
Don't forget to add the secret as env-variable. It might be helpful for the end user to set the preview URL as default.
To revalidate pages after publishing in Storyblok, you have to set up the following Webhook URL:
https://<my-url>/api/story-published?secret=<your-preview-password-or-token>
Don't forger to add the secret token as env-variable.