Image without description
  • Jacco Meijer
  • |
  • Mar 18, 2024

11ty and Github pages

Simplifying the Contentful-Gatsby-Netlfy trio.

A bit of history

Around 2018 the first projects emerged using Contentful, GatsbyJs and Netlify. This is still is a great setup for generating static sites.

Image without description
  • Jacco Meijer
  • |
  • Jan 19, 2022

Contentful, Netlify and Gatsby four years later

What did we learn from using Contentful for four years?

The main drawback? It 's a heavy solution for a simple static site. Mainly because it requires three independent services.

A simpler solution

Besides the GatsbyJs framework, the Contentful setup requires three services to work together:

  • Contentful
  • Netlify
  • Github
Image without description

Six years later, Netlify grew to be a popular platform for hosting static sites. Github pages also grew in popularity. For this specific setup, switching from Netlify to Github pages eliminates one of the three services.

11ty

If Contentful could be simplified the same way, Github would be the only service required.

Saving the content to Github as Markdown is a simple way to achieve this but brings up a new question. How to work with reusable pieces of content?

Having a closer look at Github pages learns that Github pages is driven by Jekyll and Jekyll uses the Liquid template language created by Shopify for templates.

From Jekyll it is a small step to 11ty because 11ty is the JavaScript alternative to the Ruby based Jekyll.

Replacing Gatsby with 11ty and storing the site content in Markdown allows for removing Contentful from the list of required services.

Migrating existing content

With the new setup, 11ty generates the site HTML which is then pushed to Github. This successfully replaces the Gatsby generated site.

All good! Until existing content is migrated. This brings up two areas of interest:

  1. page metadata and
  2. reusable components.

1. Page metadata

Handling page metadata is a common requirement for Static Site Generators. The Hugo generator handles this by adding metadata to the top of a Markdown page. The metadata is then called 'Front Matter'.

A quick example of Front Matter:

---
date: 2024-01-01T02:16:22-09:00
draft: false
title: Front Matter title
---

11ty uses Front Matter by default and NPM packages exist that handle the extraction from documents.

2. Reusable components

Components in a template world are commonly referred to as 'includes'. Including another piece of Markdown works as a simple component solution.

Markdown renders to HTML and Markdown allows for including HTML. This makes that complex component requirements can be handled with a HTML based solution. Some popular ones are:

  • WebC, 11ty's answer to Web Components.
  • Stencil, a popular library for building Web Components.
  • Native HTML Custom Elements and the new declarative shadow dom, finally gained Mozilla support in February 2024.
  • JSX, the popular Javascript extension by Facebook/React.

WebC is an excellent solution for reusable components. Especially when using 11ty. But, being familiar with Gatsby and React, how about using JSX functions for components?

NOTE: Zach Leatherman, author of 11ty, wrote a great post on the modern issues of styling these components.

MDX

Combining 11ty, Markdown and WebC is a common approach.

Using 11ty, Markdown and JSX together is not. This is because combining Markdown and JSX is so obvious that it has its own name. It's called MDX and mdxjs.com clearly explains how this works.

While not the most common solution, using JSX as a template language in 11ty is very well possible. Paul Everitt, the PyCharm/WebStorm Developer Advocate at JetBrains, created a JSX setup with Typescript:

Conclusion

The Contentful-Gatsby-Netlify trio can be simplified by using 11ty and Github pages. Any component solution can be used. For 11ty, WebC components is a solid choice.

Static site generator for MDX

Diving a bit deeper into MDX, it seems that using @mdx-js/esbuild with some custom logic could make Esbuild into a simple but powerful static site generator.

The quest for simplicity continues in the next post!

Image without description
  • Jacco Meijer
  • |
  • Mar 19, 2024

Esbuild as a static site generator for MDX

Static site generators gain popularity. This blog is about using Esbuild as a static site generator for MDX.


Other posts

Image without description
  • Jacco Meijer
  • |
  • Mar 21, 2024

UI Library with MDX documentation

Using the simple Render JSX plugin for Esbuild this post shows how to setup a simple UI library.

Image without description
  • Jacco Meijer
  • |
  • Mar 20, 2024

Render JSX plugin for Esbuild

Transform Esbuild generated JSX bundles to HTML pages.

Image without description
  • Jacco Meijer
  • |
  • Mar 19, 2024

Esbuild as a static site generator for MDX

Static site generators gain popularity. This blog is about using Esbuild as a static site generator for MDX.

Image without description
  • Jacco Meijer
  • |
  • Mar 18, 2024

11ty and Github pages

Simplifying the Contentful-Gatsby-Netlfy trio.

Image without description
  • Jacco Meijer
  • |
  • Mar 15, 2024

OWASP and CISSP

OWASP recommendations from the independent information security certification CISSP.

Image without description
  • Jacco Meijer
  • |
  • Jun 30, 2022

NPM7 and @npmcli/arborist

@npmcli/arborist is a powerful library that handles the new NPM 7 workspaces. This blog is about a simple make tool that uses the library.

Image without description
  • Jacco Meijer
  • |
  • May 12, 2022

Comparing React app, Nextjs and Gatsby

A new React project starts with a React toolchain. Main tools in the chains are SSR, React server components and GraphQL.

Image without description
  • Jacco Meijer
  • |
  • May 10, 2022

Versioning strategy for NPM modules

It is important to be able to bump the version of a NPM package without side effects.

Image without description
  • Jacco Meijer
  • |
  • Apr 12, 2022

React component themes and CSS variables

Creating React components with flexible themes by using CSS variables.

Image without description
  • Jacco Meijer
  • |
  • Mar 21, 2022

Content modeling with variants

The efficiency of a variant field in a content model.

Image without description
  • Jacco Meijer
  • |
  • Mar 12, 2022

Documentation

Documenting a software project is challenging. Here's a few simple guidelines that help a team writing clear documentation.

Image without description
  • Jacco Meijer
  • |
  • Mar 11, 2022

Javascript history

In 1986 David Ungar and Randall B. Smith developed Self at Xerox PARC. Inspired by Java, Scheme and Self Brendan Eich created Javascript in 1995.

Image without description
  • Jacco Meijer
  • |
  • Mar 10, 2022

On Javascript transpilers, bundlers and modules

There's Javascript transpilers, modules, bundles and bundlers. This is a brief overview of all of these.

Image without description
  • Jacco Meijer
  • |
  • Feb 11, 2022

Agile Scrum

The Agile Scrum framework is flexible enough to be used in many different ways. Here's one way of working.

Image without description
  • Jacco Meijer
  • |
  • Jan 20, 2022

What happened to Wheelroom?

Founded in 2018. Started to fly in 2020 and abandoned in 2021. What happened?

Image without description
  • Jacco Meijer
  • |
  • Jan 19, 2022

Contentful, Netlify and Gatsby four years later

What did we learn from using Contentful for four years?

Image without description
  • Jacco Meijer
  • |
  • Jan 18, 2022

Typescript interface for React UI components

How to define an interface for React UI components that prevents breaking changes.

Image without description
  • Jacco Meijer
  • |
  • Jan 17, 2022

Naming React components

What's in a name? A clear naming strategy helps developers communicate. Most devs rather spend time writing component code than wasting time on a good component name.