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
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
Install plugin using npm:
npm install eleventy-plugin-ghost --saveAdd plugin to your
.eleventy.jsconfig, 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
dotenvwith a.envfile to ensure credentials are stored in the source code. Here's an example of the.envfile:GHOST_URL=https://demo.ghost.io GHOST_KEY=22444f78447824223cefc48062
Run your Eleventy project and use the global
ghostdata variable to accessposts,pages,tagsandauthors. A customfilterPostsfilter 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
Create a
.envfile inside ofdemowith the following credentials:GHOST_URL=https://demo.ghost.io GHOST_KEY=22444f78447824223cefc48062
Amends the
.eleventy.jsfile withindemoso it points to the source code in the parent directory:// const pluginGhost = require("../"); const pluginGhost = require("eleventy-plugin-ghost");
Install the demo dependencies:
cd demo npm installRun the demo locally:
npm run dev