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-cloudflare-image-resizing

v0.3.1

Published

Plugin for generating the correct image URL of Cloudflare Image Resizing service.

Downloads

18

Readme

Eleventy Cloudflare Image Resizing plugin

Serve images through Cloudflare Image Resizing service with no hassle.

Install

npm i eleventy-plugin-cloudflare-image-resizing

Use

The plugin exports a function for configuring the shortcode:

const createCloudflareImageShortcode = require('eleventy-plugin-cloudflare-image-resizing');

module.exports = (config) => {
	config.addShortcode(
		'cloudflareImage',
		createCloudflareImageShortcode({
			zone: 'https://example.com', // optional
			mode: 'img', // optional, default
			directory: 'cloudflare-images', // optional, default
			bypass: () => process.env.NODE_ENV !== 'production', // optional, default
			cloudflareURL: () => zone + '/' + 'image' + originalURL // optional, usage example
		}),
	);
};
  1. zone is the domain name of the website. It may be omitted and the domain will be taken from headers.
  2. mode is the default shortcode mode (can be overwritten by the shortcode). Plugin supports three modes:
    1. img - shortcode outputs ready to use <img> tag.
    2. url - shortcode outputs only final Cloudflare URL.
    3. attributes - shortcode outputs <img> ready to use attributes as the object.
  3. directory is the name of the directory under the output which will contain referenced images. Plugin copies images from source to the output directory by itself. Don't use the addPassthroughCopy option with images that are referenced by the plugin because you may end up with two copies.
  4. bypass is a function that determines which image URL should be returned either from the Cloudflare service (for the production environment, by default) or from the local directory (see directory option). This function must return a boolean value. If true, a returned URL points to the Cloudflare service, otherwise - the local directory.
  5. cloudflareURL is a function that allows you to customize your cloudflare URL. cloudflareURL must have the following arguments:
    • zone
    • domain
    • options - cloudflare URL options like: format, quality, width, anim, etc.
    • originalURL - URL of your image

Shortcode has the following signature:

const result = cloudflareImage(url, options);
  1. url - it is the relative path to the image from the current page. You may set another relative from point by providing relativeTo property in options.
  2. options - it includes all options that Cloudflare URL may accept and several additional options like:
    1. relativeTo - see above.
    2. emit - overrides the global mode option and accepts the same values.
    3. densities - list of all image densities for the srcset attribute. (sizes shouldn't be defined)
    4. sizes - list of all required image widths for the srcset attribute. (densities shouldn't be defined)
    5. attributes - a map of all additional <img> attributes.
    6. domain is the domain that acts as a place from where images are taken. It may be omitted, and in that case, it will be implying that images are hosted on the current domain (which serves the whole website).

srcset attribute if defined in the attributes is not used if densities or sizes is provided.

Word from author

Have fun ✌️