GithubHelp home page GithubHelp logo

digideskio / gatsby-source-ghost Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tryghost/gatsby-source-ghost

0.0 0.0 0.0 49 KB

Source plugin for pulling data into Gatsby.js from the Ghost Public API.

Home Page: https://ghost.org

License: MIT License

JavaScript 100.00%

gatsby-source-ghost's Introduction

Gatsby Source Ghost

Source plugin for pulling data into Gatsby.js from the Ghost Public API.

Install

npm install --save gatsby-source-ghost

How to use

You need to specify three properties in your gatsby-config.js:

{
   resolve: `gatsby-source-ghost`,
   options: {
       apiUrl: `https://<your-subdomain>.ghost.io`,
       clientId: `ghost-frontend`,
       clientSecret: `<your client secret>`
   }
}

apiUrl
The admin or API URL for your Ghost site. For Ghost(Pro) customers this is your .ghost.io domain. For self hosters it is your main domain unless you have a separate admin url configured. Note that this URL should be served over HTTPS.

clientId
This is almost always ghost-frontend, unless you have a custom client, which is not yet fully supported by Ghost.

clientSecret
The secret for the ghost-frontend client, which can be found just above the </head> tag on any page on your Ghost site.

How to query

There are 4 node types available from Ghost: Post, Page, Author and Tag.

Documentation for the full set of fields made available for each resource type can be found in the Public API docs.

Posts and Pages have the same properties.

You can query Post nodes created from Ghost like the following:

{
  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
          ...
        }       
      }
    }
  }
}

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
        ...
      }
    }
  }
}

You can query Page nodes created from Ghost like the following:

{
  allGhostPage {
    edges {
      node {
        id
        slug
        title
        html
        ...
      }
    }
  }
}

You can query Tag nodes created from Ghost like the following:

{
  allGhostTag {
    edges {
      node {
        id
        slug
        name
        ...
      }
    }
  }
}

You can query Author nodes created from Ghost like the following:

{
  allGhostAuthor {
    edges {
      node {
        id
        slug
        name
        ...
      }
    }
  }
}

Copyright & License

Copyright (c) 2018 Ghost Foundation - Released under the MIT license.

gatsby-source-ghost's People

Contributors

erisds avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.