Netlify CMS & Next.js Series - Integrating Netlify CMS
Senior Full-Stack Developer with over 20 years of experience building web applications for startups, government, and higher education.
Search for a command to run...
Senior Full-Stack Developer with over 20 years of experience building web applications for startups, government, and higher education.
No comments yet. Be the first to comment.
This will be a series of posts were I setup a simple brochure site in Next.js driven by the Netlify CMS.
We're finally ready to deploy our site to Netlify! Netlify.toml Make a file at the top level of your directory called netlify.toml, and fill it with: [build] command = "npm run build && npm run export" publish = "out" The command here is referrin...
Writing this up so I have somewhere to quickly grab basic Jest setup. This information is copied from the Jest Documentation Site compressed into just the parts I'm interested in. Create folders mkdir -p <project>/src cd <project> Install and init n...

In this blog post, we'll explore the process of setting up and configuring a Postgres database using Docker and seeding it with test data. This approach can be used for a variety of apps and can be easily adapted for your own needs. We'll cover all t...

Continuing from last time, we will explore the concepts behind Create and Update functionality and provide a step-by-step guide on how to implement it in your SvelteKit application. Let's get started! Server & Client Code In SvelteKit, the server-sid...

Introduction In this post, I will explore how to create a REST API using Spring Boot and Kotlin. We will dive into the fundamentals of Spring Boot and Kotlin, explain how to set up the project, and guide you through the process of building the API st...

Introduction Welcome to the latest post in my series of Koan Battles using Kotlin and TypeScript. In this series, we'll complete a Koan in both languages and then discuss the differences between the two solutions. My goal is to help you gain a deeper...

The default method of integrating Netlify CMS with Next.js is not super flexible so lets use an alternative method... We want custom previews so lets use netlify-cms-app.
NOTE: If you're not interested in custom previews take a look at the standard Netlify CMS guide: Adding Netlify CMS to NextJS
Add the Netlify CMS dependency using the command:
yarn add netlify-cms-app
During the user sign up process the site must handle authentication redirects. The easiest way to handle this is by adding the Netlify Identity Widget to the index page header:
filename: pages/index.tsx
...
<Head>
<title>{header.title}</title>
<link rel="icon" href="/favicon.ico" />
**<script src="https://identity.netlify.com/v1/netlify-identity-widget.js" />**
</Head>
...
Lets create an admin page that loads the Netlify CMS:
filename: pages/admin.tsx
import React from "react";
import dynamic from "next/dynamic";
const AdminWithNoSSR = dynamic(
() =>
import("netlify-cms-app").then((CMS: any) => {
CMS.init();
}) as any,
{ ssr: false });
export default AdminWithNoSSR;
NOTE: We're using the Next.js dynamic method to prevent the Netlify CMS code running server side
We'll also need a file to configure Netlify CMS:
filename: public/config.yml
backend:
name: git-gateway
branch: master
media_folder: public/images
public_folder: /images
collections:
- name: "pages"
label: "Pages"
files:
- label: "Index"
name: "index"
file: "content/index.md"
fields:
- label: "Header"
name: "header"
widget: "object"
collapsed: false
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Description", name: "description", widget: "string" }
- { label: "Logo", name: "logo", widget: "image", default: "/images/devfair-logo.svg" }
- label: "Hero"
name: "hero"
widget: "object"
collapsed: false
fields:
- { label: "Heading", name: "heading", widget: "string" }
- { label: "Detail", name: "detail", widget: "markdown" }
- { label: "Hero Image", name: "image", widget: "image", default: "/images/hero.svg" }
If we go to the admin url we should see the login page:

There are lots of config options we can tweak, you can find full details of all the settings here:
For example we can set a custom logo on the admin page by adding a logo image file public/images/devfair-logo.svg then setting the logo_url setting:
...
public_folder: /images
logo_url: /images/devfair-logo.svg
collections:
...
You should now see a custom logo on the admin page:
