rsnext/examples/cms-storyblok
2020-06-10 22:23:28 +00:00
..
components Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
lib Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
pages Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
public/favicon Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
styles Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
.env.local.example Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
jsconfig.json Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
package.json Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
postcss.config.js Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
README.md Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
tailwind.config.js Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
vercel.json Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00

A statically generated blog example using Next.js and Storyblok

This example showcases Next.js's Static Generation feature using Storyblok as the data source.

Demo

https://next-blog-storyblok.now.sh/

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npx create-next-app --example cms-storyblok cms-storyblok-app
# or
yarn create next-app --example cms-storyblok cms-storyblok-app

Download manually

Download the example:

curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/cms-storyblok
cd cms-storyblok

Configuration

Step 1. Create an account on Storyblok

Create an account on Storyblok.

When signing up, select Create a new space. Its name can be anything.

Step 2. Create the Authors folder

From the dashboard, create a new folder called Authors.

  • For Default content type, select Add new.
  • Name of content type should be author.
  • Choose Blank as the content type blueprint.

Step 3. Create an author entry

In the Authors folder, create a new entry.

  • Name can be anything, such as Test Author.

After creating the entry, click Define schema.

  • Add a key called 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.

Step 4. Create the Posts folder

After publishing the author, go back to the dashboard by clicking Content on the sidebar.

This time, create a new folder called Posts.

  • For Default content type, select Add new.
  • Name of content type should be post.
  • Choose Post as the content type blueprint.

Step 5. Create a post entry

In the Posts folder, create a new entry.

  • Name can be anything.

Now, populate each field.

  • Title can be any text.
  • Image can be an image from Unsplash.
  • Intro can be any text.
  • Long Text can be any text.
  • Author should be the author created earlier.

Finally, click Publish.

You can create more posts under the Posts folder. Make sure to publish each one.

Step 6. Set up environment variables

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:

  • NEXT_EXAMPLE_CMS_STORYBLOK_API_KEY should be the API key you just copied.
  • NEXT_EXAMPLE_CMS_STORYBLOK_PREVIEW_SECRET can be any random string (but avoid spaces), like MY_SECRET - this is used for the Preview Mode.

Step 7. Run Next.js in development mode

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.

Step 8. Try preview mode

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 its 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 NEXT_EXAMPLE_CMS_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.

Step 9. Deploy on Vercel

You can deploy this Next.js app to the cloud with Vercel (Documentation).

To deploy on Vercel, you need to set the environment variables with Vercel Secrets using Vercel CLI (Documentation).

Install Vercel CLI, log in to your account from the CLI, and run the following commands to add the environment variables. Replace <NEXT_EXAMPLE_CMS_STORYBLOK_API_KEY> and <NEXT_EXAMPLE_CMS_STORYBLOK_PREVIEW_SECRET> with the corresponding strings in .env.

vercel secrets add next_example_cms_storyblok_api_key <NEXT_EXAMPLE_CMS_STORYBLOK_API_KEY>
vercel secrets add next_example_cms_storyblok_preview_secret <NEXT_EXAMPLE_CMS_STORYBLOK_PREVIEW_SECRET>

Then push the project to GitHub/GitLab/Bitbucket and import to Vercel to deploy.