077097b7f8
* Add licences to all example/package.json that lack them * Revert "Add licences to all example/package.json that lack them" This reverts commit 5d4e25012f7334772b8ef5924bc355277e827cba. * Update check-examples to remove `license` field from examples * Remove `license` from all examples. This was mentioned in vercel/next.js#27121 but it looks like it didn't end up being in the merge? Co-authored-by: JJ Kasper <jj@jjsweb.site> |
||
---|---|---|
.. | ||
components | ||
lib | ||
pages | ||
public/favicon | ||
styles | ||
.env.local.example | ||
.gitignore | ||
jsconfig.json | ||
package.json | ||
postcss.config.js | ||
README.md | ||
tailwind.config.js |
A statically generated blog example using Next.js and ButterCMS
This example showcases Next.js's Static Generation feature using ButterCMS as the data source.
Demo
https://next-blog-buttercms.vercel.app/
Deploy your own
Once you have access to the environment variables you'll need, deploy the example using Vercel:
Related examples
- WordPress
- DatoCMS
- Sanity
- TakeShape
- Prismic
- Contentful
- Agility CMS
- Cosmic
- Strapi
- Storyblok
- GraphCMS
- Kontent
- Ghost
- Blog Starter
How to use
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
Configuration
Step 1. Create an account on ButterCMS
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.
Step 2. Set up environment variables
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.
Step 3. Run Next.js in development 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.
Step 4. Try preview mode
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.
Step 5. 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.