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-transformer-screenshot

v5.13.1

Published

Gatsby transformer plugin that uses AWS Lambda to take screenshots of websites

Downloads

510

Readme

gatsby-transformer-screenshot

Plugin for creating screenshots of website URLs using an AWS Lambda Function. This plugin looks for SitesYaml nodes with a url property, and creates Screenshot child nodes with a screenshotFile field.

Live demo (source)

Data should be in a YAML file named sites.yml and look like:

- url: https://reactjs.org/
  name: React
- url: https://about.sourcegraph.com/
  name: Sourcegraph
- url: https://simply.co.za/
  name: Simply

Install

npm install gatsby-transformer-screenshot

How to use

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-screenshot`,
      options: {
        // See "Lambda setup" below to see how to create an endpoint
        screenshotEndpoint: `your-aws-endpoint`,
      }
    }
  ],
}

By default, the plugin will target nodes sourced from a YAML file named sites.yml.

To source additional node types, supply an array of the types to a nodeTypes option on the plugin.

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-screenshot`,
      options: {
        nodeTypes: [`StartersYaml`, `WhateverType`],
      },
    },
  ],
}

How to query

You can query for screenshot files as shown below:

{
  allSitesYaml {
    edges {
      node {
        url
        childScreenshot {
          screenshotFile {
            id
          }
        }
      }
    }
  }
}

screenshotFile is a PNG file like any other loaded from your filesystem, so you can use this plugin in combination with gatsby-plugin-image.

Lambda setup

You need to run a screenshot service on AWS Lamdba yourself.

AWS Lambda is a "serverless" computing platform that lets you run code in response to events, without needing to set up a server. This plugin uses a Lambda function to take screenshots and store them in an AWS S3 bucket.

First, you will need to create a S3 bucket for storing screenshots. Once you have done that, create a Lifecycle Policy for the bucket that sets a number of days before files in the bucket expire. Screenshots will be cached until this date.

To build the Lambda package, run npm run build-lambda-package in this directory. A file called lambda-package.zip will be generated - upload this as the source of your AWS Lambda. Finally, you will need to set S3_BUCKET as an environment variable for the lambda inside AWS.

To set up the HTTP interface, you will need to use AWS API Gateway. Create a new API, create a new resource under /, select "Configure as proxy resource", and leave all the settings with their defaults. Create a method on the new resource, selecting "Lambda Function Proxy" as the integration type, and fill in the details of your lambda.

Placeholder image

If your site pulls a lot of screenshots it might be beneficial to use placeholder image instead of downloading and processing all the screenshots. It will help with data sourcing and query running times.

You can use placeholder image by setting GATSBY_SCREENSHOT_PLACEHOLDER environment variable when running npm run develop:

GATSBY_SCREENSHOT_PLACEHOLDER=true gatsby develop

or by using dotenv in your gatsby-config.js and adding GATSBY_SCREENSHOT_PLACEHOLDER to .env.development file in root of your project:

GATSBY_SCREENSHOT_PLACEHOLDER=true