diff --git a/docs/advanced-features/preview-mode.md b/docs/advanced-features/preview-mode.md index 99b861ea691ef..7c59b0a1bfafd 100644 --- a/docs/advanced-features/preview-mode.md +++ b/docs/advanced-features/preview-mode.md @@ -19,6 +19,7 @@ description: Next.js has the preview mode for statically generated pages. You ca
  • Agility CMS Example (Demo)
  • Cosmic Example (Demo)
  • ButterCMS Example (Demo)
  • +
  • Storyblok Example (Demo)
  • diff --git a/docs/basic-features/data-fetching.md b/docs/basic-features/data-fetching.md index 668d5de8a27dd..683a2af53cb77 100644 --- a/docs/basic-features/data-fetching.md +++ b/docs/basic-features/data-fetching.md @@ -20,6 +20,7 @@ description: 'Next.js has 2 pre-rendering modes: Static Generation and Server-si
  • Agility CMS Example (Demo)
  • Cosmic Example (Demo)
  • ButterCMS Example (Demo)
  • +
  • Storyblok Example (Demo)
  • Static Tweet Demo
  • diff --git a/docs/basic-features/pages.md b/docs/basic-features/pages.md index 149fb490e1c2d..349547872828b 100644 --- a/docs/basic-features/pages.md +++ b/docs/basic-features/pages.md @@ -59,6 +59,7 @@ Finally, you can always use **Client-side Rendering** along with Static Generati
  • Agility CMS Example (Demo)
  • Cosmic Example (Demo)
  • ButterCMS Example (Demo)
  • +
  • Storyblok Example (Demo)
  • Static Tweet Demo
  • diff --git a/examples/cms-agilitycms/README.md b/examples/cms-agilitycms/README.md index 0a420fe0056e5..506472bee8f01 100644 --- a/examples/cms-agilitycms/README.md +++ b/examples/cms-agilitycms/README.md @@ -20,6 +20,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas - [Strapi](/examples/cms-strapi) - [Cosmic](/examples/cms-cosmic) - [ButterCMS](/examples/cms-buttercms) +- [Storyblok](/examples/cms-storyblok) - [Blog Starter](/examples/blog-starter) ## How to use diff --git a/examples/cms-buttercms/README.md b/examples/cms-buttercms/README.md index 2e72abd757870..5878ca3bfce52 100644 --- a/examples/cms-buttercms/README.md +++ b/examples/cms-buttercms/README.md @@ -17,6 +17,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas - [Agility CMS](/examples/cms-agilitycms) - [Cosmic](/examples/cms-cosmic) - [Strapi](/examples/cms-strapi) +- [Storyblok](/examples/cms-storyblok) - [Blog Starter](/examples/blog-starter) ## How to use diff --git a/examples/cms-contentful/README.md b/examples/cms-contentful/README.md index 1a74455c913b3..734f8f3c279e8 100644 --- a/examples/cms-contentful/README.md +++ b/examples/cms-contentful/README.md @@ -17,6 +17,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas - [Agility CMS](/examples/cms-agilitycms) - [Cosmic](/examples/cms-cosmic) - [ButterCMS](/examples/cms-buttercms) +- [Storyblok](/examples/cms-storyblok) - [Blog Starter](/examples/blog-starter) ## How to use diff --git a/examples/cms-datocms/README.md b/examples/cms-datocms/README.md index 3c2ff6aa021d8..c0efb04214732 100644 --- a/examples/cms-datocms/README.md +++ b/examples/cms-datocms/README.md @@ -17,6 +17,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas - [Agility CMS](/examples/cms-agilitycms) - [Cosmic](/examples/cms-cosmic) - [ButterCMS](/examples/cms-buttercms) +- [Storyblok](/examples/cms-storyblok) - [Blog Starter](/examples/blog-starter) ## How to use diff --git a/examples/cms-prismic/README.md b/examples/cms-prismic/README.md index 98895f5645080..1634e11275792 100644 --- a/examples/cms-prismic/README.md +++ b/examples/cms-prismic/README.md @@ -17,6 +17,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas - [Agility CMS](/examples/cms-agilitycms) - [Cosmic](/examples/cms-cosmic) - [ButterCMS](/examples/cms-buttercms) +- [Storyblok](/examples/cms-storyblok) - [Blog Starter](/examples/blog-starter) ## How to use diff --git a/examples/cms-sanity/README.md b/examples/cms-sanity/README.md index fc75ef0857da2..21e2012ce5eb7 100644 --- a/examples/cms-sanity/README.md +++ b/examples/cms-sanity/README.md @@ -17,6 +17,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas - [Agility CMS](/examples/cms-agilitycms) - [Cosmic](/examples/cms-cosmic) - [ButterCMS](/examples/cms-buttercms) +- [Storyblok](/examples/cms-storyblok) - [Blog Starter](/examples/blog-starter) ## How to use diff --git a/examples/cms-storyblok/.env.local.example b/examples/cms-storyblok/.env.local.example new file mode 100644 index 0000000000000..932438f2fbc96 --- /dev/null +++ b/examples/cms-storyblok/.env.local.example @@ -0,0 +1,3 @@ +# Copy this file as .env.local +NEXT_EXAMPLE_CMS_STORYBLOK_API_KEY= +NEXT_EXAMPLE_CMS_STORYBLOK_PREVIEW_SECRET= \ No newline at end of file diff --git a/examples/cms-storyblok/README.md b/examples/cms-storyblok/README.md new file mode 100644 index 0000000000000..fbb494b4ee994 --- /dev/null +++ b/examples/cms-storyblok/README.md @@ -0,0 +1,163 @@ +# A statically generated blog example using Next.js and Storyblok + +This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using [Storyblok](https://www.storyblok.com/) as the data source. + +## Demo + +[https://next-blog-storyblok.now.sh/](https://next-blog-storyblok.now.sh/) + +### Related examples + +- [WordPress](/examples/cms-wordpress) +- [DatoCMS](/examples/cms-datocms) +- [Sanity](/examples/cms-sanity) +- [TakeShape](/examples/cms-takeshape) +- [Prismic](/examples/cms-prismic) +- [Contentful](/examples/cms-contentful) +- [Agility CMS](/examples/cms-agilitycms) +- [Cosmic](/examples/cms-cosmic) +- [Strapi](/examples/cms-strapi) +- [ButterCMS](/examples/cms-buttercms) +- [Blog Starter](/examples/blog-starter) + +## How to use + +### Using `create-next-app` + +Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: + +```bash +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: + +```bash +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](https://app.storyblok.com/). + +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](https://unsplash.com/). + +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](https://unsplash.com/). +- **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): + +```bash +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](https://nextjs.org/docs/advanced-features/preview-mode). + +### Step 7. Run Next.js in development mode + +```bash +npm install +npm run dev + +# or + +yarn install +yarn dev +``` + +Your blog should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, you can post on [GitHub discussions](https://github.com/vercel/next.js/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 it’s not published. However, if you use the **Preview Mode**, you'll be able to see the change ([Documentation](https://nextjs.org/docs/advanced-features/preview-mode)). + +To enable the Preview Mode, go to this URL: + +``` +http://localhost:3000/api/preview?secret=&slug= +``` + +- `` should be the string you entered for `NEXT_EXAMPLE_CMS_STORYBLOK_PREVIEW_SECRET`. +- `` 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](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). + +To deploy on Vercel, you need to set the environment variables with **Vercel Secrets** using [Vercel CLI](https://vercel.com/download) ([Documentation](https://vercel.com/docs/vercel-cli#commands/secrets)). + +Install [Vercel CLI](https://vercel.com/download), log in to your account from the CLI, and run the following commands to add the environment variables. Replace `` and `` with the corresponding strings in `.env`. + +``` +vercel secrets add next_example_cms_storyblok_api_key +vercel secrets add next_example_cms_storyblok_preview_secret +``` + +Then push the project to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) to deploy. diff --git a/examples/cms-storyblok/components/alert.js b/examples/cms-storyblok/components/alert.js new file mode 100644 index 0000000000000..e6fd18b175c8c --- /dev/null +++ b/examples/cms-storyblok/components/alert.js @@ -0,0 +1,42 @@ +import Container from './container' +import cn from 'classnames' +import { EXAMPLE_PATH } from '@/lib/constants' + +export default function Alert({ preview }) { + return ( +
    + +
    + {preview ? ( + <> + This is page is a preview.{' '} + + Click here + {' '} + to exit preview mode. + + ) : ( + <> + The source code for this blog is{' '} + + available on GitHub + + . + + )} +
    +
    +
    + ) +} diff --git a/examples/cms-storyblok/components/avatar.js b/examples/cms-storyblok/components/avatar.js new file mode 100644 index 0000000000000..f27c58617ce63 --- /dev/null +++ b/examples/cms-storyblok/components/avatar.js @@ -0,0 +1,12 @@ +export default function Avatar({ name, picture }) { + return ( +
    + {name} +
    {name}
    +
    + ) +} diff --git a/examples/cms-storyblok/components/container.js b/examples/cms-storyblok/components/container.js new file mode 100644 index 0000000000000..fc1c29dfb0747 --- /dev/null +++ b/examples/cms-storyblok/components/container.js @@ -0,0 +1,3 @@ +export default function Container({ children }) { + return
    {children}
    +} diff --git a/examples/cms-storyblok/components/cover-image.js b/examples/cms-storyblok/components/cover-image.js new file mode 100644 index 0000000000000..7230d824f2d47 --- /dev/null +++ b/examples/cms-storyblok/components/cover-image.js @@ -0,0 +1,17 @@ +import Link from 'next/link' + +export default function CoverImage({ title, url, slug }) { + return ( +
    + {slug ? ( + + + {title} + + + ) : ( + {title} + )} +
    + ) +} diff --git a/examples/cms-storyblok/components/date.js b/examples/cms-storyblok/components/date.js new file mode 100644 index 0000000000000..6503e2986d5c0 --- /dev/null +++ b/examples/cms-storyblok/components/date.js @@ -0,0 +1,13 @@ +import { parseISO, format } from 'date-fns' +import { useEffect, useState } from 'react' + +// dateString might be null for unpublished posts +export default function DateComponent({ dateString }) { + const [date, setDate] = useState(dateString ? parseISO(dateString) : null) + useEffect(() => { + if (!date) { + setDate(new Date()) + } + }, [date]) + return date && +} diff --git a/examples/cms-storyblok/components/footer.js b/examples/cms-storyblok/components/footer.js new file mode 100644 index 0000000000000..102872d195df0 --- /dev/null +++ b/examples/cms-storyblok/components/footer.js @@ -0,0 +1,30 @@ +import Container from './container' +import { EXAMPLE_PATH } from '@/lib/constants' + +export default function Footer() { + return ( + + ) +} diff --git a/examples/cms-storyblok/components/header.js b/examples/cms-storyblok/components/header.js new file mode 100644 index 0000000000000..562e7e3eebb6a --- /dev/null +++ b/examples/cms-storyblok/components/header.js @@ -0,0 +1,12 @@ +import Link from 'next/link' + +export default function Header() { + return ( +

    + + Blog + + . +

    + ) +} diff --git a/examples/cms-storyblok/components/hero-post.js b/examples/cms-storyblok/components/hero-post.js new file mode 100644 index 0000000000000..7cdae5aad3c51 --- /dev/null +++ b/examples/cms-storyblok/components/hero-post.js @@ -0,0 +1,37 @@ +import Avatar from './avatar' +import Date from './date' +import CoverImage from './cover-image' +import Link from 'next/link' + +export default function HeroPost({ + title, + coverImage, + date, + excerpt, + author, + slug, +}) { + return ( +
    +
    + +
    +
    +
    +

    + + {title} + +

    +
    + +
    +
    +
    +

    {excerpt}

    + +
    +
    +
    + ) +} diff --git a/examples/cms-storyblok/components/intro.js b/examples/cms-storyblok/components/intro.js new file mode 100644 index 0000000000000..c3003c6196642 --- /dev/null +++ b/examples/cms-storyblok/components/intro.js @@ -0,0 +1,28 @@ +import { CMS_NAME, CMS_URL } from '@/lib/constants' + +export default function Intro() { + return ( +
    +

    + Blog. +

    +

    + A statically generated blog example using{' '} + + Next.js + {' '} + and{' '} + + {CMS_NAME} + + . +

    +
    + ) +} diff --git a/examples/cms-storyblok/components/layout.js b/examples/cms-storyblok/components/layout.js new file mode 100644 index 0000000000000..399802b095aa7 --- /dev/null +++ b/examples/cms-storyblok/components/layout.js @@ -0,0 +1,16 @@ +import Alert from './alert' +import Footer from './footer' +import Meta from './meta' + +export default function Layout({ preview, children }) { + return ( + <> + +
    + +
    {children}
    +
    +