rsnext/examples/cms-storyblok
mnjongerius 895e7df860
Patch 2 (#62147)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change
-->
### What?
Updating Example for Storyblok

### Why?
While setting up the Storyblok example to do create quick poc I noticed
some documentation missing and some code not working as expected.

### How?
- Updates documentation about Storyblok example in README
- Code change in HeroPost to make Storyblok example work as expected
2024-02-16 20:29:28 +00:00
..
components Patch 2 (#62147) 2024-02-16 20:29:28 +00:00
lib chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07:00
pages chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07: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 Add new import flow to CMS examples (#14053) 2020-06-11 23:44:23 +00:00
.gitignore Add .yarn/install-state.gz to .gitignore (#56637) 2023-10-18 16:34:48 +00:00
jsconfig.json Storyblok CMS Example (#13993) 2020-06-10 22:23:28 +00:00
package.json Maintenance: minor example dep bumps to fix moderate vulns (#56375) 2023-10-04 11:18:54 -04:00
postcss.config.js chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07:00
README.md Patch 2 (#62147) 2024-02-16 20:29:28 +00:00
tailwind.config.js chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07: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.vercel.app/

Deploy your own

Once you have access to the environment variables you'll need, deploy the example using Vercel:

Deploy with Vercel

How to use

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

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.

After creating the entry, click Define schema.

  • Add a key called title. Then click title and set the Type as Text
  • Add a key called image. Then click title and set the Type as Text
  • Add a key called intro. Then click title and set the Type as Text
  • Add a key called long_text. Then click title and set the Type as Richtext
  • Add a key called author. Then click title and set the Type as Single-Option and set Source as Stories and Restrict to content type as author

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

Step 9. Configure Image Optimization

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: '**',
        },
        {
          protocol: 'https',
          hostname: 'images.unsplash.com',
          port: '',
          pathname: '**',
        },
       ],
    },
  }

Read more about image optimization in the Documentation

Step 8. 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 9. 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 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 10. Deploy on Vercel

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

Deploy Your Local Project

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.

Deploy from Our Template

Alternatively, you can deploy using our template by clicking on the Deploy button below.

Deploy with Vercel