campjefferson / -campj-eleventy-image

1 stars 0 forks source link

NOTE: this package is deprecated. Please consider using the more robust Eleventy Image instead.



Eleventy Image Pipeline

A configurable Eleventy shortcode that builds multiple resolutions of any image.

Usage

Installation

npm install --save-dev @campj/eleventy-image

Environment Variables

Source prefix

Set the ELEVENTY_IMAGE_SRC_PREFIX environment variable if you'd like to change where your source images are pulled from.
**default: src/site

Example 1 (default)

with the default settings you'd do

{% Image src="https://github.com/campjefferson/-campj-eleventy-image/raw/master/img/someimage.jpg" %}

would transform the image located at ./src/site/img/someimage.jpg.

Example 2

ELEVENTY_IMAGE_SRC_PREFIX=images

{% Image src="https://github.com/campjefferson/-campj-eleventy-image/raw/master/someimage.jpg" %}

would transform the image located at ./images/someimage.jpg.

Path prefix

Set the ELEVENTY_PATH_PREFIX environment variable if you'd like to prepend a prefix to your image paths
**default: none

Adding to Eleventy

in .eleventy.js:

// require
const { Image } = require("@campj/eleventy-image");
module.exports = function (eleventyConfig) {
  // Shortcode
  eleventyConfig.addNunjucksAsyncShortcode("Image", Image);
  //
};

In any nunjucks template file:

Use the shortcode:

{% Image
    src = "/img/placeholder-1.jpg",
    maxWidths = [200, 500, 768, 1024, 1368]
%}

Props:

** other properties will get applied to the wrapper tag as attributes