How to make a blog with 11ty and GhostCMS


2 min read

This is a pretty easy task considering we are not using the file system, but using JSON from an external source.

Install the packages that we need

npm install @tryghost/content-api @11ty/eleventy --save

That's it.

Getting the data from Ghost

In _data/posts.js, we can make the following file:

Basically, it:

  • Require's the module
  • Setup the API to get data (setting the keys, etc)
  • Exports the posts using module.exports.

For this example, we will use the demo ghost instance located at

Setting up the layout

In a file called _includes/base.html, insert the following:

<!DOCTYPE html>
    <title>My Awesome Blog!</title>
  <body style="padding-left:32px;padding-right:32px;">
    {{ content | safe }}

Basically, this creates a basic HTML document, Changes the title to My Awesome Blog!, and inserts the content.

Setting up the list of posts

Make a new file called index.html.

layout: base.html
  My Awesome Blog

  {% for post in posts %}
  <li><a href="/posts/{{ post.slug }}">{{ post.title }}</a></li>
  {% endfor %}

This basically says: "Use the layout base.html in the folder _includes, Then, for every post from GhostCMS, make a new unordered list item with the link /post/{{ post.slug }} and the Title {{ post.title }}." Run eleventy and visit your site. It should look something like this:

We have a blog! But, If you click a link, it shows a 404 error. Lets fix that. Make a new file called posts.html and add the following:

  data: posts
  alias: post
  size: 1
permalink: posts/{{ post.slug }}/
layout: base.html

  {{ post.title }}
<div class="content">
  {{ post.html | safe }}

This basically uses 11ty's pagination feature and creates a new page for every post, then inserts the data into the page. Run eleventy again.

Great, we are finished, right? Nope. The webpage just looks, ugly. We can fix this with 1 line of CSS using water.css. Just insert the following line into _includes/base.html in the <head> tag:

<link rel="stylesheet" href="">

Run eleventy for the last. The webpage looks 100% better now! Now we have a blog. Thanks for reading!

Note: Every time you make a new post/update it, you will have to update it using the eleventy command.