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

@tanc00/gridsome-source-cockpit

v0.0.2

Published

Cockpit CMS source plugin for Gridsome

Downloads

2

Readme

Cockpit CMS source plugin for Gridsome

This package is under development and API may change before v1 is released.

Install

Use one of:

  • yarn add @tanc00/gridsome-source-cockpit
  • npm install @tanc00/gridsome-source-cockpit

Usage

module.exports = {
  plugins: [
    {
      use: '@tanc00/gridsome-source-cockpit',
      options: {
        accessToken: process.env.ACCESSTOKEN,
        host: process.env.APIHOST
      }
    }
  ]
}

You will need to provide the ACCESSTOKEN and APIHOST environment variables in a .env or similar file at the root of your project. Gridsome will automatically read this and pass in the variables to the source plugin.

For example:

APIHOST=https://my-cockpit-cms.com
ACCESSTOKEN=b90d9080711bab6e9af34fbea754c5

API limit

You can also set a limit per request if you have thousands of collections or assets and want to pull in a paged set of results. To do this set the APILIMIT environment variable, for example:

APILIMIT=100

You will also need to add a config option in your gridsome.config.js file:

module.exports = {
  plugins: [
    {
      use: '@tanc00/gridsome-source-cockpit',
      options: {
        options: {
          accessToken: process.env.ACCESSTOKEN,
          host: process.env.APIHOST
          apiLimit: process.env.APILIMIT
        }
      }
    }
  ]
}

Routes

You can configure a route per collection type by defining them in gridsome.config.js. The key is the name of the collection and the value is the path you'd like for that collection. For example:

module.exports = {
  plugins: [
    {
      use: '@tanc00/gridsome-source-cockpit',
      options: {
        accessToken: process.env.ACCESSTOKEN,
        host: process.env.APIHOST
        routes: {
          page: '/:slug',
          blogpost: '/blog/:year/:month/:slug',
        }
      }
    }
  ]
}

i18n

Fields in Cockpit can be localized into different languages. This plugin is able to import localized versions of fields. To import each language you need to specify the language code in a languages array in the plugin options, something like this:

module.exports = {
  plugins: [
    {
      use: '@tanc00/gridsome-source-cockpit',
      options: {
        accessToken: process.env.ACCESSTOKEN,
        host: process.env.APIHOST
        languages: [
          'it',
          'de'
        ]
      }
    }
  ]
}

In the example above, this plugin will add fields (if they exist and are localized) to GraphQL. Each localized field will have the two letter code appended, for example, if you have a field called intro which is localized and you have it and de as your languages you will see three fields added to GraphQL called intro, introIt and introDe

At the time of writing there is currently no officially supported method of handling i18n (internationalisation) content within Gridsome so it will be up to you to decide how you want to display and handle your translated fields.

Cockpit API configuration

Cockpit CMS must be configured to allow access to the API using a token. To set this up visit /restadmin/index and configure the Custom keys section. You may need to generate a key and also allow access to specific api paths, for example:

/api/collections/get
/api/cockpit/assets
/api/cockpit/image
/api/collections/collection
/api/collections/listCollections
/api/singletons/get
/api/singletons/listSingletons

Once configured hit Save at the bottom. You can test access by visiting an endpoint in your browser, for example:

https://my-cockpit-cms.com/api/collections/get/page?token=b90d9080711bab6e9af34fbea754c5

If you get an access denied message you'll need to check your configuration.

Cockpit Collection fields

@tanc/gridsome-souce-cockpit currently works with all collection fields with some caveats:

  • Repeater fields are added to Gridsome as JSON fields. This provides the full tree of information under a repeater field. Without it being a JSON field only repeater fields composed of a single field type would be pulled into GraphQL properly.
  • Only repeater fields at the top level are added as JSON fields. If there is a nested repeater field inside a set field this may be added properly but only if the repeater is composed of instances of a single field type.
  • Only reference fields at the top level will work as Gridsome references. If a reference field is nested inside a repeater or set field it won't work in Gridsome as a reference, although its original subfields will be available.

Future enhancements

  • Deeper field processing: Walk the entire entry tree processing deeper fields than just the top level ones to get nested reference, repeater and set fields fully working.
  • Support singletons: Currently singletons are not processed by this source plugin