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

v0.4.0

Published

A Gatsby source plugin for fetching photos from Unsplash

Downloads

4

Readme

gatsby-source-plugin-unsplash

A Gatsby plugin for fetching photos from an Unsplash collection.

Demo :confetti_ball:

URL: https://gatsby-source-unsplash.netlify.com/

Repo: https://github.com/mattrothenberg/gatsby-unsplash-demo

Photos are sourced from this collection.

Installation

First, install the plugin with the package manager of your choice (NPM or Yarn).

yarn add gatsby-source-plugin-unsplash

Before you start configuring the plugin, you need to register for an Unsplash API Developer account. Once you have an account, you'll be able to grab an access key that you'll use to make authenticated API requests.

I know it's a little weird, but Unsplash's API endpoints call for passing along a clientId, but in the Unsplash Developer UI, this is called an Access Key.

Next, add the following to your gatsby.config.js. Only clientId and collectionId are required. I'd recommend following Gatsby's instructions for sourcing these values from an environment file, so you're not hard-coding sensitive keys in your codebase.

// Not necessary, but recommended!
require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})

module.exports = {
  {
    resolve: `gatsby-source-plugin-unsplash`,
    options: {
      collectionId: process.env.COLLECTION_ID,
      clientId: process.env.CLIENT_ID,
      perPage: 100
    },
  }
}

Now, you should have two new queries at your disposal when you run your Gatsby site, allUnsplashPhoto and unsplashPhoto. As you might guess, the former is used to pull all photos from the specified collection, whereas the latter is used to pluck individual images from that collection, given some filtering criteria.

You have available to you all of the fields from this API response, https://unsplash.com/documentation#get-a-collections-photos.

Additionally, this plugin adds a localImage field to each node so that you can use these images with gatsby-image and transform them with Sharp.

For example, the following query would yield –

{
  allUnsplashPhoto {
    edges {
      node {
        id
        urls {
          full
        }
      }
    }
  }
}

And this query,

{
  unsplashPhoto(id: { eq: "Ikf439frOLg" }) {
    id
    urls {
      full
    }
  }
}

...would yield:

.

Features

To be totally fair, this isn't the only Unsplash plugin for Gatsby. In fact, this plugin is largely inspired by https://www.gatsbyjs.org/packages/gatsby-source-unsplash/.

One improvement made by this plugin, however, is that it adds a localImage field to each node for greater flexibility around presenting the images.

{
  allUnsplashPhoto(limit: 10) {
    edges {
      node {
        id
        user {
          username
        }
        localImage {
          childImageSharp {
            fluid(maxWidth: 400, maxHeight: 250) {
              ...GatsbyImageSharpFluid
            }
          }
        }
      }
    }
  }
}

Todo

  • [ ] Support multiple collections
  • [ ] Support different endpoints