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-slicknode

v0.0.5

Published

Gatsby source plugin for Slicknode Headless GraphQL CMS

Downloads

2

Readme

GatsbyJS Slicknode Source Plugin

Source plugin for loading content from Slicknode Headless GraphQL CMS into Gatsby.

This source plugin downloads all content nodes from the CMS and adds the content as Gatsby nodes to the Gatsby GraphQL API. The content can then be transformed, extended etc. with all the other Gatsby plugins.

Features:

Links:

Installation

Install the source plugin via npm:

npm install gatsby-source-slicknode

Configuration

Add the source plugin to the gatsby-config.js file of your project and customize the configuration:

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-slicknode',
      options: {
        // Endpoint to your Slicknode GraphQL API (Required)
        endpoint: 'https://<your-slicknode-project-endpoint>',
  
        // Download all images and add a localFile field to the slicknode `Image` types.
        // The file can then be used in combination with gatsby-transformer-sharp and gatsby-image
        // Default: true
        downloadImages: true,

        // If true, loads the content in preview mode.
        // default: false
        preview: false,

        // Path to the directory where the Slicknode stores fragments of the individual types
        // Those can then be customized to add or exclude specific fields from the nodes that are 
        // added to the gatsby store, add filtered connections etc.
        // If you are using multiple Slicknode APIs in the same projects, use differnet paths for each project
        // Default: slicknode-fragments
        fragmentsPath: 'slicknode-fragments',

        // The prefix for typenames of the types that are added to the Gatsby GraphQL schema
        // If you are using multiple gatsby-source-slicknode plugin instances, use different namespaces for
        // each instance.
        // Default: Slicknode_
        typePrefix: 'Slicknode_',
      },
    }
  ],
};

Usage

For each content type the root query fields will be added to the Gatsby GraphQL schema. Check out the GraphiQL playground for query capabilities: https://localhost:8000/___graphql

Customizing Fragments

The gatsby-source-slicknode plugin generates fragments for each custom type in your Slicknode schema that implements the Node interface. The entire object is then sourced into Gatsby according to the specified fragment. The source plugin creates files for each fragment in the directory specified in the config option fragmentPath (default to ./slicknode-fragments).

You can customize the fragments in the directory to load additional data like many-to-many relations that are not included by default, or you can remove fields if you don't want to include certain fields in your Gatsby schema.

Note: When you make changes to existing types in your Slicknode API, you have to update already generated fragments to also apply the changes to the Gatsby GraphQL API

Image Transforms

To use the images with the gatsby-image plugin, install the required plugins and add them to your configuration:

// In your gatsby-config.js
module.exports = {
  /* Your site config here */
  plugins: [
    {
      resolve: 'gatsby-source-slicknode',
      options: {
        endpoint: 'https://<your-slicknode-endpoint>',
        
        // Enable image download for the transformations
        downloadImages: true,
      },
    },
    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`,
  ],
}

Then use the image fragments of the image sharp plugin to generate optimized images for assets loaded from the Slicknode API, for example:

query GetBlogPostsQuery {
  allSlicknodeBlogPost {
    edges {
      node {
        image {
          localFile {
            childImageSharp {
              fluid {
                ...GatsbyImageSharpFluid
              }
            }
          }
        }
      }
    }
  }
}

Sourcing Multiple Slicknode APIs

To source data from multiple Slicknode APIs, add the configuration for both endpoints and choose differnet fragmentsPath and typePrefix settings for each API, for example:

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-slicknode',
      options: {
        endpoint: 'https://<your-primary-slicknode-endpoint>',
        fragmentsPath: 'slicknode-fragments-primary',
        typePrefix: 'SlicknodePrimary_'
      },
    },
    {
      resolve: 'gatsby-source-slicknode',
      options: {
        endpoint: 'https://<your-secondary-slicknode-endpoint>',
        fragmentsPath: 'slicknode-fragments-secondary',
        typePrefix: 'SlicknodeSecondary_'
      },
    },
    // ...
  ],
}