• This repository has been archived on 05/May/2023
  • Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This starter repository is no longer maintained.

Next.js + Contentful Blog Starter

A screenshot of the Next.js Contentful starter home page

This is an example repository for you to use to create a new blog site using Next.js and Contentful, using Contentful's GraphQL API.

Read more about the GraphQL API.

View the demo site

Click here to explore the demo site that uses this repository as its source code.

Getting set up

Fork the repository to your GitHub account and clone it to your local machine.

#using git
git clone [email protected]:whitep4nth3r/nextjs-contentful-blog-starter.git

#using the GitHub CLI
gh repo clone whitep4nth3r/nextjs-contentful-blog-starter

Configuring your development environment

Install dependencies

In a terminal window, navigate to the project directory and install dependencies with npm.

cd nextjs-contentful-blog-starter
npm install

Set your environment variables

At the root of the project, create a new .env.local file. Add the following environment variable names to the file:

CONTENTFUL_SPACE_ID=
CONTENTFUL_ACCESS_TOKEN=

Using example content from Contentful

You can choose to use your own Contentful account, or connect to the example space that we've provided.

If you'd like to view some example content in your development environment to get a feel for how it works, you can use the provided credentials in env.local.example which will connect your code to the example space provided by Contentful.

Using your own Contentful account

To get started with your own Contentful space, sign up for free.

Create a new space inside your Contentful account. Go to Settings > General Settings, and make a note of your space ID.

A screenshot of space ID settings in the Contentful UI

Generate a Content Delivery API access token for your Contentful space.

A screenshot of access token settings in the Contentful UI

Add your space ID and access token to your .env.local file.

Importing the starter content model and example content into your own Contentful space

To get started quickly on your own version of the application, you can use the Contentful CLI to import the content model and the example content from the starter into your own Contentful space — without touching the Contentful UI!

Install the Contentful CLI

#using homebrew
brew install contentful-cli

#using npm
npm install -g contentful-cli

#using yarn
yarn global add contentful-cli

Authenticate with the CLI

Open a terminal and run:

contentful login

A browser window will open. Follow the instructions to log in to Contentful via the CLI.

Import the content model and example content

The following command in your terminal, ensuring you switch out SPACE_ID for your new space ID.

cd nextjs-contentful-blog-starter/setup

contentful space import --space-id SPACE_ID --content-file content-export.json

You should see this output in the terminal. The import will take around 1 minute to complete.

A screenshot of the import command running in a terminal

Refresh Contentful in your browser, navigate to the content model tab, and you'll find the content types have been imported into your space. You'll find the example content by clicking on the content tab.

A screenshot of the imported content model in the Contentful UI

Running the application in development

Navigate to the project directory in a terminal window and run:

npm run dev

Deploy this site to Netlify

Deploy with Netlify

During the deploy process, add the following environment variables to Netlify. Use the same credentials as you set up in your local development environment.

CONTENTFUL_SPACE_ID
CONTENTFUL_ACCESS_TOKEN

Publish via webhooks

After you deploy the site to Netlify you can configure it to build whenever new a new entry is published in Contentful. To configure this navigate to your site settings on Netlify and go to the Build & Deploy tab. Find the Build hooks section and add a new build hook. Name the build hook something like Contentful and select your production branch.

A screenshot of adding a build_hook in the Netlify UI

Copy the generated URL and navigate to Settings > Webhooks in your Contentful space. Under Webhook Templates click Add next to the Netlify template. Add the URL you just copied and click Create webhook.

A screenshot of adding a build hook in the Contentful UI

Now when you publish an entry in your Contentful space it will trigger a build of your production branch on Netlify.

Configure Next.js preview mode

In your Contentful space, go to Settings > Content preview and add a new content preview. Under content preview URLs check Blog Post and add this URL

https://$NETLIFY_URL/api/preview?secret=$SECRET&slug={entry.fields.slug}&contentType=blogPost

Replacing $NETLIFY with the URL of your site deployed on Netlify and $SECRET which a secret value that you generate. Store this value as you will add to your Netlify environment variables in a moment.

Check Page Content and add this URL

https://$NETLIFY_URL/api/preview?secret=$SECRET&slug={entry.fields.slug}&contentType=pageContent

Replacing the variables with the same values you used above. Navigate to your site on Netlify and go to Site settings > Build & Deploy > Environment and add the following environment variables

CONTENTFUL_PREVIEW_SECRET
CONTENTFUL_PREVIEW_ACCESS_TOKEN

Set CONTENTFUL_PREVIEW_SECRET to the value you generated above and used for $SECRET in the preview URLs. Set CONTENTFUL_PREVIEW_ACCESS_TOKEN to your Contentful Content Preview API access token which can be found under Settings > API keys.

Trigger a new deploy of your site on Netlify so the new variables are applied and you should now be able to enter Preview mode by clicking the preview button on relevant content entries.

More Repositories

1

fretonator

The ultimate interactive free guitar theory tool.
TypeScript
81
star
2

puppeteer-demo

How to use Puppeteer to take webpage screenshots and generate dynamic Open Graph images for social sharing
JavaScript
65
star
3

thingoftheday

thingoftheday is a lightweight microblogging site powered by Contentful and vanilla HTML, CSS and JavaScript.
JavaScript
49
star
4

mk2-p4nth3rblog

My website is the best website.
JavaScript
40
star
5

whattheframework

Choose your next JavaScript framework based on the features you need in your project.
Astro
33
star
6

the-claw-webring

The Claw Webring: list of members
32
star
7

p4nth3rblog

My 2021 personal blog site built with NextJS and Contentful — now deprecated.
JavaScript
32
star
8

randomcodegenerator.lol

Need some code for your project? We've got you covered. Choose your language. Choose how much code. BÄM! You got code.
JavaScript
32
star
9

pantherworld

View your p4nth3rworld inventory, read the manual, and more!
Vue
21
star
10

findsomethingtodo

Bored? Want to procrastinate and look productive? Find something ToDo.
Astro
17
star
11

womenwhostream.tech

JavaScript
15
star
12

p4nth3rb0t-mainframe

Sends Twitch events over websockets to stream overlays and The Claw Discord server.
TypeScript
14
star
13

whitep4nth3r

JavaScript
13
star
14

p4nth3rlabs

Twitch chat, Twitch stream alerts and other fun stuff
TypeScript
12
star
15

random-code

The npm package that powers randomcodegenerator.lol.
JavaScript
11
star
16

fancy-business-card

A demo repository to show how to create a CLI tool that outputs a business card to the terminal.
JavaScript
9
star
17

contentful-graphql-vs-rest

A look at the difference between how to fetch and render linked assets and entries in the Rich Text field in Contentful.
JavaScript
9
star
18

the-claw-webring-widget

The Claw Webring Widget as a web component for your website.
JavaScript
8
star
19

p4nth3rball

Because everyone needs more interactive Twitch stream games!
JavaScript
8
star
20

gameofcodes.party

Test your HTTP status code knowledge.
JavaScript
7
star
21

nextjs-advanced-middleware-on-netlify-demo

Learn how to use @netlify/next Advanced Middleware to transform the response of a statically generated page in Next.js.
JavaScript
7
star
22

p4nth3rdrop

TypeScript
6
star
23

hacking-lighthouse

Examples of how you can (or cannot) hack your Lighthouse performance score.
Astro
6
star
24

theclaw.team

Build stuff, learn things, love what you do. The Claw is science and technology — for everyone.
JavaScript
6
star
25

next-netlify-starter

A one-click starter project for Next and Netlify.
JavaScript
6
star
26

whitep4nth3r.com

The fifth rebuild of whitep4nth3r.com.
Astro
4
star
27

zengoweb-overlay

zengoweb-overlay
CSS
3
star
28

twitch-chat-roulette

JavaScript
3
star
29

image-loading-strategies

Astro
3
star
30

randomwebsitegenerator.lol

JavaScript
3
star
31

getting-started-with-netlify-edge-functions

This tutorial will take you through using Edge Functions on Netlify to build a hello world example, and transform an HTML template using geolocation data at the edge.
HTML
3
star
32

p4nth3rchat

DEPRECATED
Svelte
3
star
33

js-arrow-regular-funcs

Experiments in JavaScript
JavaScript
2
star
34

nextjs-netlify-blog-template

2
star
35

html-css-fundamentals

Supporting materials for my HTML + CSS fundamentals series on YouTube.
HTML
2
star
36

whitep4nth3r-links

A demo site using astro.build. Deployed on Netlify.
Astro
2
star
37

rfc-822

Build an RFC-822 date-time with JavaScript for RSS feeds.
JavaScript
2
star
38

battlep4nth3r

Battlesnake snake for summer league 2021.
JavaScript
2
star
39

what-is-bem

A small explainer repository that shows how to use the BEM syntax in CSS.
HTML
2
star
40

p4nth3rworld

Astro
2
star
41

ticket-app-demo

Demo code for the blog post: How to build a social image sharing app with Cloudinary and Next.js
JavaScript
2
star
42

image-404-fallbacks-and-monitoring

HTML
1
star
43

contentful-csv-import

A JavaScript example to show how to import a CSV file into Contentful via the CMA
JavaScript
1
star
44

twitchlisten

Listen to your Twitch chat.
JavaScript
1
star
45

edge-functions-examples

JavaScript
1
star
46

blog-metrics-contentful-app

A Contentful app that generates a reading time for blog post entires.
TypeScript
1
star
47

super-contact-form

super-contact-form
CSS
1
star
48

whitep4nth3r.codes

This is a deprecated repository.
Svelte
1
star
49

netlify-preview-contentful-app

Preview your draft content in Contentful on your static site before your publish to production.
TypeScript
1
star
50

get-random-entry

A single function to retrieve a random entry from an array
JavaScript
1
star
51

serverless-monitoring-vercel

Investigations into monitoring serverless and edge functions on Vercel with Sentry.
JavaScript
1
star
52

rate-limits-for-science

JavaScript
1
star
53

personalize-with-http-referer

Use Netlify Edge Functions to intercept a request to a static page, check the value of the HTTP referer header, and enhance the response of the HTML before it's returned to the browser. No client-side JavaScript required.
HTML
1
star