This is sample Next.js starter site that uses Agility CMS and Cloudinary together and aims to be a foundation for building fully static sites using Next.js, Agility CMS and Cloudinary.
New to Agility CMS? Sign up for a FREE account
- Cloudinary is an amazing tool to help you unleash the full potential of your online media.
- Optimize, transform, and combine your images to create great digital experiences
- Upload and stream high quality adaptive videos from your website
- Sign up for a free Cloudinary account here
- Uses our
@agility/nextpackage to make getting started with Agility CMS and Next.js easy - Connected to a sample Agility CMS Instance for sample content & pages
- Uses Cloudinary for Cloudinary Images and videos (*** additional setup required - see below! ***)
- Uses the
getStaticPropsfunction from Next.js to allow for full SSG (Static Site Generation) - Supports
next/imagefor image optimization - Supports full Page Management
- Supports Preview Mode
- Uses
revalidatetag with Vercel to enable ISR (Incremental Static Regeneration) builds - Provides a functional structure that dynamically routes each page based on the request, loads a Page Templates dynamically, and also dynamically loads and renders appropriate Agility CMS Page Modules (as React components)
This starter uses Tailwind CSS, a simple and lightweight utility-first CSS framework packed with classes that can be composed to build any design, directly in your markup.
It also comes equipped with Autoprefixer, a plugin which use the data based on current browser popularity and property support to apply CSS prefixes for you.
To start using this Starter, sign up for a FREE account and create a new Instance using the Blog Template.
- Clone this repository
- Run
npm installoryarn install - Rename the
.env.local.examplefile to.env.local - Retrieve your
GUID,API Keys (Preview/Fetch), andSecurity Keyfrom Agility CMS by going to Settings > API Keys.
This starter builds on top of the Blog Starter Content Model, and has a special integration hosted in this repo. You'll need to deploy it to Vercel to get that working.
-
Create your Cloudinary Account and get your Credentials
- Ensure your .env.local has
CLOUDINARY_CLOUD_NAMEandCLOUDINARY_API_KEYfrom your Cloudinary dashboard.
- Ensure your .env.local has
-
Deploy to Vercel
- Push your clone of this repo into a new repo in Github
- Login to Vercel and create a new project from your new repo
- Create environment variables for the values in your
.env.localfile - When the site deploys, take note of the URL
https://[yourproject].vercel.app
-
Add the Cloudinary UI Extension to Agility
- Login to your blog instance in Agility and navigate to Settings -> UI Extensions
- Replace the path there with YOUR URL + custom-fields.js:
https://[yourproject].vercel.app/custom-field.js
- Save.
- Refresh your Browser window
-
Add Cloudinary fields to the Post Content Model in Agility
- We're going to add 2 new fields to this model and change one of the existing fields to not be required.
- Navigate to Models -> Content Models -> Post
- Click Edit on the Blog Cloudinary Image field
- Uncheck Required Field
- Click the Update Field button
- Click Add Field
- Field Name:
Cloudinary Image - Field Type:
Custom Field - Custom Field Type:
Cloudinary Image - Click the Add Field button
- Field Name:
- Click Add Field
- Field Name:
Cloudinary Video - Field Type:
Custom Field - Custom Field Type:
Cloudinary Video - Click the Add Field button
- Field Name:
- Click Save
-
Create a new Post with a Cloudinary Image and/or Video
- Navigate to Content -> Blog Posts
- Click + New
- Fill out the fields, but DON'T choose a
Blog Cloudinary Image - On the
Cloudinary Imagefield click Choose- You should see your Cloudinary Media library. You can upload or choose an existing image.
- On the
Cloudinary Videofield, click Choose- You can upload or choose an existing video.
When running your site in development mode, you will see the latest content in real-time from the CMS.
yarn installyarn dev
To update content locally without restarting your dev server, run yarn cms-pull
To clear your content cache locally, run yarn cms-clear
npm installnpm run dev
To update content locally without restarting your dev server, run npm run cms-pull
To clear your content cache locally, run npm run cms-clear
When running your site in production mode, you will see the published from the CMS.
yarn buildyarn start
npm run buildnpm run start
- Check out the
Videocomponent incomponents/common/Video.js. It uses Cloudinary'sAdvancedVideocomponent to automagically display a video based on the public id. - Check out the
lib/cloudinary-tools.jsfile - it has a bunch of methods for manipulating Cloudinary images. - I bet you can make a ton of improvements on this - if you do, let me know (@joelvarty)
This starter supports TypeScript out of the box. If you would like to use TypeScript in your project, simply rename your files with a .ts extension to start taking advantage of Typescript concepts such as types and interfaces to help describe your data.
- To create a new Page Module, create a new React component within the
/components/agility-pageModulesdirectory. - All of the Page Modules that are being used within the site need to be imported into the
indexfile within the/components/agility-pageModulesdirectory and added to theallModulesarray:
import RichTextArea from "./RichTextArea";
import FeaturedPost from "./FeaturedPost";
import PostsListing from "./PostsListing";
import PostDetails from "./PostDetails";
import Heading from "./Heading";
import TextBlockWithImage from "./TextBlockWithImage";
const allModules = [
{ name: "TextBlockWithImage", module: TextBlockWithImage },
{ name: "Heading", module: Heading },
{ name: "FeaturedPost", module: FeaturedPost },
{ name: "PostsListing", module: PostsListing },
{ name: "PostDetails", module: PostDetails },
{ name: "RichTextArea", module: RichTextArea },
];
- To create a new Page Template, create a new React component within the
/components/agility-pageTemplatesdirectory. - All of the Page Template that are being used within the site need to be imported into the
indexfile within the/components/agility-pageTemplatesdirectory and added to theallTemplatesarray:
import MainTemplate from "./MainTemplate";
const allTemplates = [
{ name: "MainTemplate", template: MainTemplate }
];
Since this is a static site, how can editors preview content in real-time as they are making edits within Agility CMS? Vercel supports Previews out of the box! Simply paste the address of your site deployed on Vercel into your Agility Sitemap Configuration (Settings > Sitemaps), and use it as your Preview Deployment.
If you have feedback or questions about this starter, please use the Github Issues on this repo, join our Community Slack Channel or create a post on the Agility Developer Community.