Gatsby Starter Henlo is the most advanced Decap CMS starter for Gatsby.js. We built it with Page Builder setup in mind. All pages are created out of programmable blocks, aiming to provide the best DX & admin UX possible.
This repo contains an example website that is built with Gatsby, and Decap CMS.
It follows the JAMstack architecture by using Git as a single source of truth, and Netlify for continuous deployment, and CDN distribution.
- Support for Gatsby v5
- πͺ Battle-tested starting point for small & large web projects
- π Form Builder that enables Admins to create multiple forms with ease & Netlify Forms integration.
- π Darkmode support
- πΊ Sitemaps using
gatsby-plugin-sitemap
- π₯ Perfect score on Lighthouse for SEO, Accessibility and Performance
- πββοΈ TailwindCSS support with PostCSS & Tailwind Merge
- π Support for Gatsby API functions
- π Crazy fast images with
gatsby-plugin-image
- π΅οΈββοΈ Complete SEO configuration with graphql fragment and reusable components based on Head API
- Netlify deploy configuration
- Example pages, collections, CMS configuration with Decap CMS & hooks
- Readme template for custom projects
- Easy Decap CMS configuration using Manual Initialization
- ..and more
- Node 20
- Gatsby CLI
- Netlify CLI
Decap CMS can run in any frontend web environment, but the quickest way to try it out is by running it on a pre-configured starter site with Netlify. Use the button below to build and deploy your own copy of the repository:
After clicking that button, youβll authenticate with GitHub and choose a repository name. Netlify will then automatically create a repository in your GitHub account with a copy of the files from the template. Next, it will build and deploy the new site on Netlify, bringing you to the site dashboard when the build is complete. Next, youβll need to set up Netlifyβs Identity service to authorize users to log in to the CMS.
$ gatsby new [SITE_DIRECTORY_NAME] https://github.com/clean-commit/gatsby-starter-henlo
$ cd [SITE_DIRECTORY_NAME]
$ yarn dev
Pulldown a local copy of the Github repository Netlify created for you, with the name you specified in the previous step
$ git clone https://github.com/[GITHUB_USERNAME]/[REPO_NAME].git
$ cd [REPO_NAME]
$ yarn && yarn dev
To test the CMS locally, you'll need to start your local development server & run local instance of Decap CMS
$ yarn dev
$ yarn cms
// or
$ npx decap-server
Your admin configuration will be available at http://localhost:8000/admin
We've added additional commands for quick deployments with Netlify CLI. To deploy the website to Netlify simply run.
$ yarn deploy:prod
The website will build locally and then deploy to production.
Before deploying to Netlify, you need to:
- Define GATSBY_APP_URL to your domain
- Update redirects in netlify.toml to reflect your website (example is set up)
βββ cms # Decap CMS configuration
β βββ blocks
β βββ collections
β βββ fields
β βββ previews
β βββ cms.js
βββ content # Your content lives here
β βββ authors
β βββ blog
β βββ forms
β βββ pages
βββ public
βββ src
β βββ api # Gatsby functions should be placed here
β βββ blocks # Blocks that create sections
β βββ components # Reusable components
β β βββ UI # UI specialized components
β βββ hooks # Hooks used in the project
β βββ lib # misc
β βββ pages
β βββ resolvers
β β βββ Image.js # Required for previews
β β βββ Link.js # Resolves links to gatsby and outside links
β βββ settings # Place for theme settings
β βββ styles
β βββ templates # Templates used to render page types
β βββ page-builder.js
β βββ post.js
βββ static
βββ _headers
βββ .env.example # Example env -> GATSBY_APP_URL is required to run the app
βββ gatsby-config.js # Config files for gatsby
βββ gatsby-node.js # Page generation setup & types interferrence
βββ tailwind.config.js # Tailwind configuration
Follow the Decap CMS Quick Start Guide to set up authentication, and hosting.
Important
This template can be mostly changed by the user within the CMS itself (Settings type). For sitemaps to work correctly, you'll need to provide ENV variable GATSBY_APP_URL
which defaults to https://example.com, this url will be used in setting up meta values in the head of the documents and links URL in the CMS.
CMS configuration was placed within cms
directory in the root of the project. This allows us to work efficiently on fields and collections without mixing CMS config with Gatsby code.
Henlo uses Manual Initialization to take advantage of componetized approach to managing configuration for Decap CMS. Thanks to that you don't have to control the CMS from centralized YAML file.
To ensure best experience we use 2 custom widgets that are maintained by us -> ID Widget that provides unmutable IDs for content items and Permalink Widget that enables you to create custom permalinks with ease.
import CMS from 'decap-cms-app'
import { Widget as UuidWidget } from 'netlify-cms-widget-id'
import { Widget as PermalinkWidget } from 'netlify-cms-widget-permalink'
import authors from './collections/authors'
import pages from './collections/pages'
import posts from './collections/posts'
import settings from './collections/settings'
import PagePreview from './previews/Page'
// Preview for all PageBuilder based pages
const config = {
config: {
load_config_file: false,
display_url: process.env.GATSBY_APP_URL, // Enables urls based on env variable
local_backend: true,
backend: {
name: 'git-gateway',
},
slug: {
encoding: 'ascii',
clean_accents: true,
},
media_folder: '/static/img',
public_folder: '/img',
collections: [pages, posts, authors, settings],
},
}
CMS.registerPreviewStyle('../commons.css')
CMS.registerPreviewTemplate('pages', PagePreview)
CMS.registerWidget(UuidWidget)
CMS.registerWidget(PermalinkWidget)
CMS.init(config)
Blocks are defined in cms/blocks/index.js
file. We're leveraging use of exported functions and variables from other fields to avoid repetition within the code.
This is extremely important due to the way GraphQL works with Markdown based files. Each field will have to be present on all page queries -> we can't differetiate between different sections.
That's why it's important to reuse names of fields, hence usage of imports.
import { Buttons, Title, Content, SelectField, ImageField } from '../fields';
const Config = {
label: 'Blocks',
name: 'blocks',
widget: 'list',
types: [
{
label: 'Hero',
name: 'hero',
widget: 'object',
fields: [
Title,
Content,
Buttons,
SelectField('default', ['default', 'centered', 'full']),
],
},
...
To add new block you have tp add new Type
to cms/blocks/index.js
file, and modify Blocks
fragment located in src/components/PageBuilder.js
As you can see below we're adding all fields used by all sections. This causes issues with Gatsby's Schema Inference. Gatsby needs an example of the field to know what type of field it is.
That's why we rely on dont-remove.md
this file contains all possible fields used in the starter, so you're never encounter a problem with types inference!
export const query = graphql`
fragment Blocks on MarkdownRemarkFrontmatter {
blocks {
type
title
content
columns {
title
content
}
photo {
image {
childImageSharp {
gatsbyImageData(
width: 800
quality: 72
placeholder: DOMINANT_COLOR
formats: [AUTO, WEBP, AVIF]
)
}
}
alt
}
variant
buttons {
button {
content
url
variant
}
}
}
}
`
To keep the GraphQL query small, we opt to reuse the field names across blocks, but if new type is added it has to be defined in graphql using createSchemaCustomization function. Without the definition you may encounter errors during build process.
Favicons can be generated using this Favicon Generator After generating the icons, drop the contents of downloaded file into static/img/favicons
directory
Since 0.4.0 Henlo supports gatsby-plugin-preload-fonts
plugin out of the box. To create the preload cache you need to start development server and then run preload-fonts
command. This will generate the font-preload-cache.json
file in the root of your project. When your projects builds fonts will be added automatically to head of the document.
yarn dev
yarn preload-fonts
Gatsby tends to add a lot of polyfills to support older browser versions. In package.json file you can adjust which sites your project should support. As default Henlo will use defaults
setting. If you want to learn more about the browser support visit official Gatsby How-To Guide on this subject
Contributions are always welcome, no matter how large or small. Before contributing, please read the code of conduct.
Here's a list of helpful articles that will help you with your first steps using Henlo!