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-statamic-g4

v1.0.2

Published

Gatsby plugin for sourcing data from Statamic CMS

Downloads

3

Readme

🔥 Whats new in this fork

This fork allowes us set defaults value for any field which comes from statamic api as null. It also adds Option to pass collection query params for sorting, filtering etc.

You have option to set default values globally or collection based

/*
* Any query parameter you want to pass globally like 'sort=-title&filter[featured]=true'
* ref: https://statamic.dev/rest-api#filtering
*/
globalQueryParams: 'sort=-title'

/*
* Default key value pair for null values.
* It will be merged with default value if defined on collections level
*/
globalDefaultValues: { 
  avatar: {id: "", permalink: ""}
}

collections: [
      { 
        handle: 'docs', 
        defaultValues: { 
          video: "",
          content: "",
          avatar: {
            id: "",
            permalink: ""
          }
        },
        queryParams: "sort=-title" // optional
      }
      ,
      'fieldtypes',
      'knowledge-base',
      'modifiers',
      'tags',
      'variables',
    ],

Gatsby Source Statamic

A Gatsby source plugin for Statamic 3 which will allow you to pull data from Statamic's Content API into your Gatsby site.

Install

  npm i gatsby-source-statamic -S

How to use

Sample Config

// In your gatsby-config.js
plugins: [
{
  resolve: `gatsby-source-statamic`,
  options: {
    /*
    * The rest api route prefix that your Statamic site is using.
    * If not set, it uses the default of 'api'
    *
    * https://statamic.dev/rest-api#customizing-the-api-url
    */
    restApiRoutePrefix: 'api',
    /*
     * The base URL of the Statamic site without the trailing slash. This is required.
     * Example : 'http://statamic-docs.test'
     */
    baseUrl: `http://statamic-docs.test`,
    /*
     * Custom URL's to make use of Statamic's built in filtering, sorting, pagination, etc.
     * The key is used as the name for the node in GraphQl
     *
     * https://statamic.dev/rest-api#filtering
     * https://statamic.dev/rest-api#sorting
     * https://statamic.dev/rest-api#selecting-fields
     * https://statamic.dev/rest-api#pagination
     */
    customUrls: {
      fieldtypesTitlesSortedReverse:
        'http://statamic-docs.test/api/collections/fieldtypes/entries?sort=-title',
    },
    /*
    * Statamic Collections
    *
    * https://statamic.dev/rest-api#entries
    */
    collections: [
      'docs',
      'fieldtypes',
      'knowledge-base',
      'modifiers',
      'tags',
      'variables',
    ],
    /*
    * Statamic Taxonomies
    *
    * https://statamic.dev/rest-api#taxonomy-terms
    */
    taxonomies: ['tags', 'types'],
    /*
    * If true, adds Statamic Globals
    *
    * https://statamic.dev/rest-api#globals
    */
    globals: true,
    /*
    * If true, adds Statamic Users
    *
    * https://statamic.dev/rest-api#users
    */
    users: true,
    /*
    * Statamic Assets
    *
    * https://statamic.dev/rest-api#assets
    */
    assets: ['main'],
  },
},

Config options

| Key | Value | Required | | ----------- | -------------------------------------------------------------------------------------------------- | -------- | | apiUrl | String: the API URL | Yes | | baseUrl | String: the base URL of your Statamic site | Yes | | customUrls | Object: Allows you to add custom URL's to take advantage of Statamtic's filtering, sorting, etc. | No | | collections | Array[String]: names of your Statamic Collections | No | | taxonomies | Array[String]: names of your Statamic Taxonomies | No | | globals | Boolean: if true, adds Statamic Globals | No | | users | Boolean: if true, adds Statamic Users | No | | assets | Array[String]: names of your Statamic Assets | No |

How to query

Get all of the titles from the 'docs' collection sorted in ASC order

query MyQuery {
  allCollectionDocs(sort: {fields: [title], order: ASC}) {
    edges {
      node {
        title
      }
    }
  }
}

GraphQL Naming

The naming conventions for various Statamic resources within GraphQL are as follows (using the example config above):

| Statamic Resource | GraphQL Name | | ----------------- | ------------------------------------------------------------------------- | | customURLS | the key of the customURLS object: ie allFieldtypesTitlesSortedReverse | | collections | allCollectionDocs, allCollectionKnowledgeBase, etc. | | taxonomies | allTaxonomyTags, allTaxonomyTypes | | globals | allGlobals | | users | allUsers | | assets | allAssetsMain |