JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q25943F
  • License ISC

Access the Ghost Content API in Eleventy 👻🎛

Package Exports

  • eleventy-plugin-ghost

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eleventy-plugin-ghost) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eleventy-plugin-ghost

npm

Import your Ghost content directly into Eleventy as global data.

Note: This plugin currently uses a development version of Eleventy which includes addGlobalData(), tread carefully

See the live demo and the demo directory in the repo to see it all in action.

Installation

  1. Install plugin using npm:

    npm install eleventy-plugin-ghost --save
  2. Add plugin to your .eleventy.js config, ensuring to add your Ghost url and Content API key. Check out the Ghost docs for how to create a Content API key:

    const pluginGhost = require("eleventy-plugin-ghost");
    
    require("dotenv").config();
    const { GHOST_URL, GHOST_KEY } = process.env;
    
    module.exports = (eleventyConfig) => {
      eleventyConfig.addPlugin(pluginGhost, {
        url: GHOST_URL,
        key: GHOST_KEY,
        version: "v3",
      });
    };

    The example above is using dotenv with a .env file to ensure credentials are stored in the source code. Here's an example of the .env file:

    GHOST_URL=https://demo.ghost.io
    GHOST_KEY=22444f78447824223cefc48062
  3. Run your Eleventy project and use the global ghost data variable to access posts, pages, tags and authors. A custom filterPosts filter comes bundled with the plugin to help with post and page filtering depending on tags or authors. For example:

    {% for post in ghost.posts | filterPosts("tags", tag.slug) %}
      <li><a href="/{{ post.slug }}/">{{ post.title }}</a></li>
    {% endfor %}

Development

  1. Create a .env file inside of demo with the following credentials:

    GHOST_URL=https://demo.ghost.io
    GHOST_KEY=22444f78447824223cefc48062
  2. Amends the .eleventy.js file within demo so it points to the source code in the parent directory:

    // const pluginGhost = require("../");
    const pluginGhost = require("eleventy-plugin-ghost");
  3. Install the demo dependencies:

    cd demo
    npm install
  4. Run the demo locally:

    npm run dev