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

eleventy-plugin-sanity-image

v0.1.1

Published

## Alpha Release

Downloads

13

Readme

Use Sanity's Asset Pipeline with 11ty

Alpha Release

This plugin is a template helper to connect Sanity's Asset Pipelines to your 11ty templates for images. This is currently in early stages.

Installation

npm install eleventy-plugin-sanity-image

Then in your .eleventy.js file, you'll need to require this package and initialize your plugin.

const sanityImage = require('../../eleventy-plugin-sanity-image/';
module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(sanityImage, {
    client: sanityClient // This is your Sanity connection object
  })
}

Once this is initialized, you've got access to 3 new shortcodes:

// Get sanity cdn URLs for your image with optional mutations
{% imageUrlFor sanityImageObject, optionalWidthValue %}
{% croppedUrlFor sanityImageObject, widthValue, heightValue %}

// Get a responsive <img> with srcset and sizes
{% responsiveImage sanityImageObject, "comma delimited list of image sizes for srcset", "html sizes attr content", "optional classes listed"}

imageUrlFor

The imageUrlFor tag will return a URL to your image on the Sanity CDN. You can pass it a width to get a specific-width image.

If you want your image to respect the crop and hotspot functionality in your Studio, be sure to pass the entire image object and not just the reference to the asset (though this will work, it just won't respect an editor's choices).

croppedUrlFor

The croppedUrlFor tag will return a URL for your image on the Sanity CDN cropped to the specify width and height specified. If you.

If you want your image to respect the crop and hotspot functionality in your Studio, be sure to pass the entire image object and not just the reference to the asset (though this will work, it just won't respect an editor's choices).

responsiveImage

The responsiveImage shortcode will return an img element with responsive srcset and sizes with properly sized images pulled from Sanity's asset pipeline.

Arguments

The responsiveImage tag accepts 4 arguments

sanityImageObject (required)

The first argument in the tag is the required image object. If you want the image to respect a user's crop/hotspot in your Studio.

srcSet (optional)

The second argument in the tag is the optional srcset override. This will be a string of comma-delimited numbers: "300, 500, 800, 1000". This will create a srcset attribute with those image sizes (in pixels). The images will be returned from Sanity's asset pipeline with those widths.

sizes (optional)

The third argument is the optional sizes override. By default, the plugin assumes sizes="100vw" for maximum flexibility. There are plenty of responsive-related reasons for overriding this option. For more information on the (sometimes confusing) sizes attr, see this CSS Tricks article.

classes (optional)

If you want to add a class to the image that's being added, you can provide a final argument to add a space-delimited list of classes to go in the html class attr.