Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TryGhost/gatsby-source-ghost
Source plugin for pulling data into Gatsby.js from the Ghost Public API.
https://github.com/TryGhost/gatsby-source-ghost
gatsby gatsby-source gatsbyjs ghost
Last synced: 30 days ago
JSON representation
Source plugin for pulling data into Gatsby.js from the Ghost Public API.
- Host: GitHub
- URL: https://github.com/TryGhost/gatsby-source-ghost
- Owner: TryGhost
- License: mit
- Created: 2018-08-17T14:50:40.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-01T13:38:18.000Z (2 months ago)
- Last Synced: 2024-11-06T06:42:07.754Z (about 1 month ago)
- Topics: gatsby, gatsby-source, gatsbyjs, ghost
- Language: JavaScript
- Homepage: https://ghost.org
- Size: 716 KB
- Stars: 175
- Watchers: 14
- Forks: 45
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gatsby Source Ghost
Source plugin for pulling data into [Gatsby.js](https://www.gatsbyjs.org/) from [Ghost](https://ghost.org), using the Ghost [Content API](https://docs.ghost.org/api/content/).
* **Demo:** https://gatsby.ghost.org
* **Gatsby Starter** https://github.com/TryGhost/gatsby-starter-ghost
* **Documentation:** https://docs.ghost.org/api/gatsby/## Install
`yarn add gatsby-source-ghost`
`npm install --save gatsby-source-ghost`
## How to use
Plugin configuration for `gatsby-config.js`:
```
{
resolve: `gatsby-source-ghost`,
options: {
apiUrl: `https://.ghost.io`,
contentApiKey: ``,
version: `v5.0` // Ghost API version, optional, defaults to "v5.0".
// Pass in "v4.0" if your Ghost install is not on 5.0 yet!!!
}
}
````apiUrl`
Ghost Content API URL - for Ghost(Pro) customers this is your `.ghost.io` domain, it’s the same URL used to view the admin panel, but without the `/ghost` subdirectory. This should be served over https.`contentApiKey`
The "Content API Key" copied from the "Integrations" screen in Ghost Admin.If you want to keep these values private (if your site is not public) you can do so using [environment variables](https://www.gatsbyjs.org/docs/environment-variables/).
## How to query
There are 5 node types available from Ghost: Post, Page, Author, Tag, and Settings.
Documentation for the full set of fields made available for each resource type can be
found in the [Content API docs](https://docs.ghost.org/api/content/). Posts and Pages have the same properties.**Example Post Query**
```
{
allGhostPost(sort: { order: DESC, fields: [published_at] }) {
edges {
node {
id
slug
title
html
published_at
...
tags {
id
slug
...
}
primary_tag {
id
slug
...
}
authors {
id
slug
...
}
}
}
}
}
```**Filter Posts by Tag**
A common but tricky example of filtering posts by tag, can be achieved like this (Gatsby v2+):
```
{
allGhostPost(filter: {tags: {elemMatch: {slug: {eq: $slug}}}}) {
edges {
node {
slug
...
}
}
}
}
```**Query Settings**
The settings node is different as there's only one object, and it has the properties [listed here](https://docs.ghost.org/api/content/#settings).
```
{
allGhostSettings {
edges {
node {
title
description
lang
...
navigation {
label
url
}
}
}
}
}
```**Query Other Node Types**
The Post, Page, Author and Tag nodes all work the same. Use the node type you need in this query:
```
{
allGhost${NodeType} {
edges {
node {
id
slug
...
}
}
}
}
```# Copyright & License
Copyright (c) 2013-2023 Ghost Foundation - Released under the [MIT license](LICENSE).