Building static sites with Contentful and Ruby

Published on June 7, 2016

Contentful + Ruby feature Image

Subscribe for updates

Build better digital experiences with Contentful updates direct to your inbox.

Not every web project needs a complex tech stack behind it: sometimes a handful of static pages is just enough. Blogs, personal websites and landing pages are the most common examples that come to mind.

For the Ruby world, we've built Contentful integrations for Jekyll and Middleman, which conveniently happen to be the most popular static site generators.

Why static, really

A quick recap on what we really like about static sites and what some of the drawbacks are (if you want to go into little more details, see our CMS for static sites guide):

Pros

  • No databases. Host the entire site in plain HTML+CSS+JavaScript.

  • It's fast. No server processing means that a site can be fully cached.

  • Inexpensive hosting. Serve your site from mostly anywhere at surprisingly low prices. (There are free hosting providers, too.)

Cons

  • Content remains the same. Every content update requires a new build and deploy.

  • No server, no logic. Since there is no server, any kind of extra logic (authentication, logging, and so on) needs to be handled by an external service.

Static but dynamic

Normally running a static website means having to manage content manually – for instance, in plain-text, Markdown-formatted files – which is probably not the most elegant approach in the world. Contentful fixes this by offering an authoring environment that feels like an ordinary CMS (without the noise, though): write your thoughts in the Contentful Web App, enjoy the speed and simplicity of a static setup. It's a clear win-win.

Integration for Middleman

  1. Add contentful_middleman to the Gemfile and add this block to the config.rb file:

  1. Run the contentful command:

  1. You're done! All your Contentful data is in the data folder, and can be accessed from the templates.

If curious, you're welcome to take a look at some more detailed tutorials.

Integration for Jekyll

  1. Add jekyll-contentful-data-import to the :plugins group in the Gemfile, and add this block to the _config.yml file:

  1. Run the contentful command:

  1. You're done! All your Contentful data is in the _data folder, and can be accessed from the templates.

If curious, you're welcome to take a look at some more detailed tutorials.

What's next

As I said before, this is not the perfect setup — there are some cons to it. Nevertheless, it's a good fit for a lot of use cases, which I encourage you to try and explore.

In a future post I'll show how to automate this process using webhooks and CircleCI to have a free automated deployment service. Fun times ahead!

Subscribe for updates

Build better digital experiences with Contentful updates direct to your inbox.

Meet the authors

David Litvak

David Litvak

Senior Solution Architect

Contentful

David is a Ruby and Python evangelist, agile devotee, frustrated sports legend, and formerly a solution architect at Contentful. He spends most of his days either coding or slaying orcs and beasts in his favorite role playing games.

Related articles

Migrating your website to Contentful? This article will line out the steps you need to take to ensure your migration process is as smooth as possible.
Guides

Migrating to Contentful from Wordpress is far easier than it may seem

July 10, 2024

To learn more about a new way of page caching with Netlify and Contentful, we explore how to render content on the fly for faster builds with Jamstack.
Guides

How to generate unlimited CDN-cached pages with Netlify and Contentful

April 5, 2022

We held a poll to ask developers about their favorite JavaScript frameworks. These are the 12 best JavaScript frameworks according to our Discord community.
Guides

Building an app? These are the best JavaScript frameworks in 2025

June 27, 2024

Contentful Logo 2.5 Dark

Ready to start building?

Put everything you learned into action. Create and publish your content with Contentful — no credit card required.

Get started