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-plugin-cockpit

v1.0.39

Published

Gatsby source plugin for Cockpit headless CMS API.

Downloads

89

Readme

gatsby-plugin-cockpit

This source plugin pulls Cockpit Headless CMS data to aGatsbyJS, a static site generator for React.

Resources

Install

npm install --save gatsby-plugin-cockpit

##How to use

Add the following to gatsby-config.js

  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `src`,
        path: `${__dirname}/src/`,
      },
    },
    {
      resolve: 'gatsby-plugin-cockpit',
      options: {
        cockpitConfig: {
          baseURL: 'http://localhost:8888',
          folder: '/cockpit',
          accessToken: '4d659efb084077fd24aeb4871d4386',
          collections: ['posts'],
          regions: ['footer'],
          customComponents: [],
        },
      },
    },
  ],

Options

| Option | | Default | Description | | -------------------- | ---------- | ------- | ------------------------------------------------------------ | | baseURL | required | none | The url to you Cockpit installation | | folder | optional | '' | The folder of your Cockpit installation | | accessToken | required | none | A valid API access token to you cockpit installation. See the Cockpit Documentation | | collections | optional | [] | The specific Cockpit collections you want to fetch. If empty all collections will be fetched. | | regions | optional | [] | The specific Cockpit regions you want to fetch. If empty all regions will be fetched. | | customComponents | optional | [] | If you have defined some custom components for you cockpit layout fields and want them to be parsed for image fields. |

How to Query

You can query collections, regions and assets.

Query Collections

Collections are converted into nodes. For example a posts collections is transformed into post nodes. So you can you allPost and post in your GraphQL queries.

allPost {
    edges {
        nodes {
            id
            ...
        }
    }
}

Query Assets

Assets are converted into Gatsby filesystem files and can be fetched with allFile or file.

allFile {
    edges {
        nodes {
            id
            publicURL
            ...
        }
    }
}

Query Regions

Regions are available in GraphQL as region nodes. So if you have a footer region in Cockpit with a col1 and a col2 field you can use following GraphQL query:

footer: region(name: { eq: "footer" }) {
	values {
		col1
		col2
	}
}

Query Child Nodes From Cockpit Fields

The Gatsby CollectionLink, Asset and Image fields will be parsed and transform into corresponding GraphQL nodes.

CollectionLink Field

The CollectionLink field links a collection to another collection. Here an example with players and teams collections.

allPlayer {
	edges {
        nodes {
            name
            role
            team {
                name
            }            
        }
	}
}

###Asset Field

The asset field gets extended with a localFile attribute linking to the corresponding file node.

For example, if you have a candidates collection with a name and a pdf as an asset field. So You can get the PDF URL with following GraphQL query:

allCandidate {
	edges {
        nodes {
            name
            pdf {
            	localFile {
	                publicURL                    
            	}
            }            
        }
	}
}

Image Field

Like the asset field, the image field gets extended with a localFile attribute linking to the corresponding file node.

Given a post collection with title, content and preview. You can use gatsby-image plugin in your GraphQL query and take advantage of Gatsby's image processing features.

allPost {
	edges {
        nodes {
            title
            content
            preview {
            	localFile {
                    childImageSharp {
                        sizes(maxWidth: 2000, quality: 90) {
                            ...GatsbyImageSharpSizes_withWebp
                        }
                    }                    
            	}
            }            
        }
	}
}

Layout Field

The layout field enables us to visually arrange components. It is even possible to define custom components corresponding to React Components we will us in Gatsby. This may be done with the LayoutComponents addon.

Given a page collection with title and content. You can do the following query:

allPage {
	edges {
        nodes {
            title
            content {
            	component
		        settings {
                    # component fields
                    ...
		        }
            }    
            content_parsed
            content_files {
                id
                publicURL
                # normal file node
            }
        }
	}
}
  • fieldname gives you the components with their settings
  • fieldname_parsed gives you the the same than field name but in an object. It enables you to ignore the type of components in the query and just getting all the component settings.
  • fieldname_files gives you all the file nodes present in the layout.