Skip to main content

Eleventy and Ghost

Eleventy is a good fit for a lightweight Ghost front-end. Ghost remains the CMS: editors write posts, manage pages, upload images, and handle publishing in Ghost Admin. Eleventy reads that content from the Content API when the site builds. For most Eleventy sites, use the official JavaScript Content API client. It is maintained as part of the TryGhost SDK and works in Node.js during Eleventy builds. Use the Admin API only for private server-side scripts, such as imports or custom publishing tools. Do not put an Admin API key in client-side JavaScript.

Prerequisites

This configuration requires basic knowledge of JavaScript and HTML templates. You will also need:
  • A running Ghost site, either self-hosted or on Ghost(Pro)
  • A custom integration in Ghost Admin so you can copy the Content API URL and key
  • An Eleventy project
Create the Content API key from Settings -> Integrations in Ghost Admin. For more detail, see Content API authentication.

Start from a new Eleventy site

If you already have an Eleventy site, skip to the Content API setup. Otherwise, create a small project and install Eleventy:
Eleventy documents the same project setup in the official Eleventy docs.

Install the Ghost Content API client

If you started with an existing Eleventy site, install the Ghost Content API client:
Add your Ghost credentials to environment variables. A local .env file is fine if your deployment platform loads it and you keep it out of source control.
For Ghost(Pro), the URL is usually your .ghost.io URL. For self-hosted Ghost, use the public URL for your Ghost install.

Fetch Ghost content with a global data file

Eleventy global data files make API data available to every template. Create _data/ghost.js:
Ghost 6.0 and later limit each browse request to 100 records, so static builds need pagination. The helper above follows the meta.pagination.next value until there are no more pages. See pagination for building static sites and Content API pagination for the underlying API behavior.

List posts on the home page

Create index.njk and read from the ghost data object:

Create one page per post

Use Eleventy pagination with a page size of 1 to create a static page for every Ghost post.
Ghost returns post HTML from content written in Ghost Admin. Rendering it with the Nunjucks safe filter is normal for a trusted CMS source, but do not use it for untrusted user-submitted HTML.

Create tag and author pages

The same ghost data object includes tags and authors. For example, this creates one archive page per tag:
For larger sites, pre-group posts by tag in _data/ghost.js so templates do less filtering work.

Run Eleventy locally

Once the data file and templates are in place, start Eleventy’s local development server:
Eleventy serves the site at http://localhost:8080/ by default.

Use the Admin API from private scripts

The Admin API can create, update, and publish content. It is useful for migrations or custom editorial tooling, but it is not needed to render a public Eleventy front-end. Install the Admin API client only where the key stays private:
Run Admin API scripts on your own machine, in CI, or on a server. Never ship GHOST_ADMIN_API_KEY to the browser.

Next steps

Read the Content API JavaScript client docs for available endpoints and options. Eleventy’s global data files and pagination docs explain how API data becomes static pages.