Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topics/gatsby-source-lever #2042

Merged
merged 25 commits into from
Sep 9, 2017
Merged

Topics/gatsby-source-lever #2042

merged 25 commits into from
Sep 9, 2017

Conversation

sebastienfi
Copy link
Contributor

@sebastienfi sebastienfi commented Sep 7, 2017

gatsby-source-lever

Source plugin for pulling data into Gatsby from Lever.co.

Wish list

  • gatsby source plugin for Lever.co
  • tests
  • example site

Install

npm install --save gatsby-source-lever

How to use

// In your gatsby-config.js
  plugins: [
    {
      resolve: 'gatsby-source-lever',
      options: {
        // Your Lever site instance name.
        site: 'lever',
        // Set verboseOutput to true to display a verbose output on `npm run develop` or `npm run build`
        // It can help you debug specific API Endpoints problems
        verboseOutput: false,
      },
    },
  ]

GraphQL Query to get all jobs

  allLever {
    edges {
      node {
        id
        lever_id
        createdAt
        text
        hostedUrl
        applyUrl
        categories {
          commitment
          location
          team
        }
        description
        descriptionPlain
        lists {
          text
          content
        }
        additional
        additionalPlain
      }
    }
  }

Site's gatsby-node.js example

If you wish to create Gatsby Pages for each Lever.co jobs, you can modify your gatsby-node.js.

const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slash = require(`slash`)

exports.createPages = ({ graphql, boundActionCreators }) => {
  const { createPage } = boundActionCreators
  return new Promise((resolve, reject) => {
    // The “graphql” function allows us to run arbitrary
    // queries against the local WordPress graphql schema. Think of
    // it like the site has a built-in database constructed
    // from the fetched data that you can run queries against.

    // ==== PAGES (LEVER) ====
    graphql(
      `
      {

          allLever {
            edges {
              node {
                id
              }
            }
          }

      }
    `
    )
      .then(result => {
        if (result.errors) {
          console.log(result.errors)
          reject(result.errors)
        }

        // Create Lever pages.
        const pageTemplate = path.resolve('./src/templates/page.js')
        // We want to create a detailed page for each
        // lever node. We'll just use the ID for the slug.
        _.each(result.data.allLever.edges, edge => {
          // Gatsby uses Redux to manage its internal state.
          // Plugins and sites can use functions like "createPage"
          // to interact with Gatsby.
          createPage({
            // Each page is required to have a `path` as well
            // as a template component. The `context` is
            // optional but is often necessary so the template
            // can query data specific to each page.
            path: `/${edge.node.id}/`,
            component: slash(pageTemplate),
            context: {
              id: edge.node.id,
            },
          })
        })
      })
      // ==== END PAGES ====

      // resolve() must be called at the end so Gatsby knows that we're done add pages.
      .then(resolve())
  })
}

@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit 4205469

https://deploy-preview-2042--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit 9cdbb84

https://deploy-preview-2042--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Sep 7, 2017

Deploy preview ready!

Built with commit 7dd73ee

https://deploy-preview-2042--gatsbygram.netlify.com

@sebastienfi
Copy link
Contributor Author

@KyleAMathews I don't know why Travis CI fails here, any idea ?

image

@KyleAMathews
Copy link
Contributor

@sebastienfi that's a console.log not a failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants