npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-source-takeshape

v2.0.1

Published

Use the TakeShape CMS as the data source for your Gatsby website.

Downloads

5

Readme

gatsby-source-takeshape

Use the TakeShape CMS as the data source for your Gatsby website.

Learning Resources

Using TakeShape with Gatsby

Installing

For use with Gatsby 3.x:

$ npm install --save gatsby-source-takeshape

For use with Gatsby 2.x:

$ npm install --save gatsby-source-takeshape@1

After you install the plugin, add it to your gatsby-config.js like this:

require('dotenv').config()

module.exports = {
  siteMetadata: {
    title: 'Gatsby Source TakeShape Example',
  },
  plugins: [
    {
      resolve: 'gatsby-source-takeshape',
      options: {
        apiKey: process.env.TAKESHAPE_TOKEN,
        projectId: process.env.TAKESHAPE_PROJECT,
      },
    },
  ],
}

.env variables

Like many projects out there, you can use dotenv to load a .env file with variables in your project's directory.

It would look something like this:

TAKESHAPE_PROJECT=<paste project id here>
TAKESHAPE_TOKEN=<paste API key here>

Make sure .env is included in your .gitignore so you don't accidentally commit your API key!

Options

| Name | Type | Description | | ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | apiKey | string | Your API Key from your project. You'll need dev or ci permissions. Create in the API Keys section under the projects dropdown. | | projectId | string | Your project ID from your TakeShape project. (see note below) | | batch | boolean | Set to true to batch queries that happen around the same time. By default, each query is a separate network request. See gatsby-source-graphql for more performance tuning tips. Default: false | | fetchOptions | object | Additional options to pass in with the second argument to fetch. | | dataLoaderOptions | object | Advanced. Override or set options passed to Dataloader. Dataloader is used if batch is true. | | throttle | boolean | Throttle queries based on the x-ratelimit-limit response header. Enabling throttling will slow down your build, but will reduce the risk of hitting your API rate limit. Regardless of throttling, 429 errors are handled with exponential backoff. Default false |

You can get your project ID from the URL when logged in to a project on the TakeShape. For example, the URL might look like this: https://app.takeshape.io/projects/b878915b-0f45-406b-b036-8ec76be92d7c In this case, the project ID is b878915b-0f45-406b-b036-8ec76be92d7c

Data Queries

Here is an extremely simple query from the hello world example:

import React from 'react'
import {graphql} from 'gatsby'

export const query = graphql`
  query {
    takeshape {
      helloWorld: getHelloWorld {
        content
      }
    }
  }
`

const IndexPage = ({data}) => <>{data.takeshape.helloWorld.content}</>

export default IndexPage

More advanced examples can be found in the shape-portfolio-gatsby sample project.

You can use the API Explorer in TakeShape to help build your queries. You can get there from "API Explorer" under the project menu. More help can be found in the documentation.

Image Queries

You can use Gatsby's GraphQL queries to pull objects suitable for use with the gatsby-image plugin. TakeShape's fixed and fluid fields will provide objects that support the base64 blur up effect, provide srcSets for responsive images, and faster page loads.

Note: Because of limitations in how Gatsby handles third-party schemas you must include the path field on your image queries for the fixed and fluid fields to work properly.

Fixed

import React from 'react'
import Img from 'gatsby-image'

export const query = graphql`
  query HomepageQuery {
    takeshape {
      homepage: getHomepage {
        title
        image {
          path // <-- this is important, see note above
          fixed(width: 400, height: 400) {
            ...GatsbyTakeShapeImageFixed
          }
        }
      }
    }
  }
`

const Homepage = ({data}) => (
  <>
    <h1>{data.takeshape.homepage.title}</h1>
    <Img fixed={data.takeshape.homepage.image.fixed} />
  </>
)

export default Homepage

Fluid

import React from 'react'
import Img from 'gatsby-image'

export const query = graphql`
  query HomepageQuery {
    takeshape {
      homepage: getHomepage {
        title
        image {
          path // <-- this is important, see note above
          fluid(maxWidth: 400, maxHeight: 400) {
            ...GatsbyTakeShapeImageFluid
          }
        }
      }
    }
  }
`

const Homepage = ({data}) => (
  <>
    <h1>{data.takeshape.homepage.title}</h1>
    <Img fluid={data.takeshape.homepage.image.fluid} />
  </>
)

export default Homepage

Args

Image queries support a number of arguments. Take a look at the type defs to see what you can do.

There is also the imgixParams argument which allows you to pass in arbitrary imgix filters as a query param-formatted string, e.g., crop=faces,edges&txt=Hello%20World!.

Developing

This plugin needs to be run inside of a Gatsby project. See example/README.md for instructions on running the example.

The following scripts are useful when developing:

  • pnpm run lint
  • pnpm run test
  • pnpm run build

Contributing

Open an issue or PR and we'll take a look!

License

MIT