This example showcases Next.js's Static Generation feature using ButterCMS as the data source.
https://next-blog-buttercms.now.sh/
Once you have access to the environment variables you'll need, deploy the example using Vercel:
- WordPress
- DatoCMS
- Sanity
- TakeShape
- Prismic
- Contentful
- Agility CMS
- Cosmic
- Strapi
- Storyblok
- GraphCMS
- Kontent
- Blog Starter
Execute create-next-app
with npm or Yarn to bootstrap the example:
npx create-next-app --example cms-buttercms cms-buttercms-app
# or
yarn create next-app --example cms-buttercms cms-buttercms-app
First, create an account on ButterCMS.
After signing up, you’ll be presented with the API key. We’ll use this in the next step.
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
:
BUTTERCMS_API_KEY
should be set as the API key.BUTTERCMS_PREVIEW_SECRET
can be any random string (but avoid spaces), likeMY_SECRET
- this is used for Preview Mode.
When you sign up to ButterCMS, it creates an example blog post automatically. You can run Next.js in development mode to view a blog containing this example post.
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, post on GitHub discussions.
To try preview mode, create a blog post:
- Set the Title as
Draft Post Test
. - Fill the content and summary with dummy text.
- Set the Featured Image by downloading some image from Unsplash.
Most importantly, do not publish the blog post. Instead, click Save Draft.
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=draft-post-test
<secret>
should be the string you entered forBUTTERCMS_PREVIEW_SECRET
.
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.
Tip: You can set the preview URL on ButterCMS.
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.