Skip to content

Commit

Permalink
Fix and clarify Ghost sourcing page (#19411)
Browse files Browse the repository at this point in the history
* Fix and clarify Ghost sourcing page

* Update docs/docs/sourcing-from-ghost.md

Co-Authored-By: Mikhail Novikov <freiksenet@gmail.com>
  • Loading branch information
2 people authored and LB committed Nov 21, 2019
1 parent e81c45c commit f86d8c6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/docs/sourcing-from-ghost.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {

## Generating pages

Once the source plugin is set up, you can use the `createPages` API in `gatsby-node.js` to create queries on your Ghost data with GraphQL. In this example, Gatsby iterates over each post returned by the Ghost API and generates a new page with that data, using the `post.js` template file.
Once the source plugin is set up, you can use the [`createPages` API](/docs/node-apis/#createPages) in `gatsby-node.js` to run queries against your Ghost data with GraphQL. In this example, Gatsby iterates over each post returned by the Ghost API and generates a new page with that data, using the `post.js` template file.

There are several ways to structure queries depending on how you prefer to work, but here's a very minimal example:

Expand Down Expand Up @@ -113,6 +113,8 @@ exports.createPages = async ({ graphql, actions, reporter }) => {

## Outputting data

The code above will create pages in the root of the site at `/`, with the path being the slug of the post.

Then, within the `post.js` template, you can determine exactly how and where you want to output data on each page. Again, you'll use GraphQL to query individual fields, so a simple example looks something like this:

```javascript:title=templates/post.js
Expand All @@ -139,10 +141,10 @@ export default Post
export const postQuery = graphql`
query($slug: String!) {
ghostPost(slug: { eq: $slug }) {
id
title
slug
feature_image
html
}
}
`
Expand Down

0 comments on commit f86d8c6

Please sign in to comment.