examples/cms-storyblok/README.md
This example showcases Next.js's Static Generation feature using Storyblok as the data source.
https://next-blog-storyblok.vercel.app/
Once you have access to the environment variables you'll need, deploy the example using Vercel.
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example cms-storyblok cms-storyblok-app
yarn create next-app --example cms-storyblok cms-storyblok-app
pnpm create next-app --example cms-storyblok cms-storyblok-app
Create an account on Storyblok.
When signing up, select Create a new space. Its name can be anything.
Authors folderFrom the dashboard, create a new folder called Authors.
author.author entryIn the Authors folder, create a new entry.
Test Author.After creating the entry, click Define schema.
picture. Then click picture and set the Type as Asset and select Images.Then upload an image to picture. You can use an image from Unsplash.
Finally, after uploading, click Publish.
Posts folderAfter publishing the author, go back to the dashboard by clicking Content on the sidebar.
This time, create a new folder called Posts.
post.post entryIn the Posts folder, create a new entry.
After creating the entry, click Define schema.
title. Then click title and set the Type as Textimage. Then click title and set the Type as Textintro. Then click title and set the Type as Textlong_text. Then click title and set the Type as Richtextauthor. Then click title and set the Type as Single-Option and set Source as Stories and Restrict to content type as authorNow, populate each field.
Finally, click Publish.
You can create more posts under the Posts folder. Make sure to publish each one.
Go to the Settings menu for your space, and click API-Keys.
Then copy the preview token on the page.
Next, copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):
cp .env.local.example .env.local
Then set each variable on .env.local:
STORYBLOK_API_KEY should be the API key you just copied.STORYBLOK_PREVIEW_SECRET can be any random string (but avoid spaces), like MY_SECRET - this is used for the Preview Mode.To safely allow optimizing images, define a list of supported URL patterns in next.config.js. Use the following configuration to allow Storyblok assets and Unspash image URL's
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'a.storyblok.com',
port: '',
pathname: '**',
search: '',
},
{
protocol: 'https',
hostname: 'images.unsplash.com',
port: '',
pathname: '**',
search: '',
},
],
},
}
Read more about image optimization in the Documentation
npm install
npm run dev
# or
yarn install
yarn dev
Your blog should be up and running on http://localhost:3000! If it doesn't work, you can post on GitHub discussions.
To try preview mode, create another post like before (you can try duplicating), but do not publish it - just save it:
Now, if you go to the post page on localhost, you won't see this post because it’s not published. However, if you use the Preview Mode, you'll be able to see the change (Documentation).
To enable the Preview Mode, go to this URL:
http://localhost:3000/api/preview?secret=<secret>&slug=<slug>
<secret> should be the string you entered for STORYBLOK_PREVIEW_SECRET.<slug> should be the post's slug (which can be seen on the Config section).You should now be able to see the draft post. To exit the preview mode, you can click Click here to exit preview mode at the top.
You can deploy this app to the cloud with Vercel (Documentation).
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and import to Vercel.
Important: When you import your project on Vercel, make sure to click on Environment Variables and set them to match your .env.local file.
Alternatively, you can deploy using our template by clicking on the Deploy button below.