0.5.0 • Published 2 years ago

eleventy-plugin-srcset v0.5.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

This Eleventy plugin generates responsive image markup along with the corresponding image files.

It can be used in two ways:

  1. The manually inserted shortcode, {% srcset %}
  2. The automatic filter mode, which finds images based on a provided CSS selector

Configuration

The plugin can be configured by passing a config object when adding the plugin, e.g.:

eleventyConfig.addPlugin( pluginSrcsetImg, {
  srcsetWidths: [540, 900, 1024],
  autoselector: '.post-content img',
  createCaptions: true
});

Configuration added will override the defaults given in the table below.

ValueDetailsDefault
autoselectorSpecifies the CSS selector used to automatically find elements you want to generate images and markup for. Set this to null if you do not want to find images automatically.'.page-body img'
srcsetWidthsAn array of the breakpoint widths used to generate images 320, 480, 640, 960, 1280, 1600
fallbackWidthThe width for the fallback 'src' image640
fallbackHeightThe height for the fallback 'src' image, when null the image will be automatic based on the aspect ratio and fallbackWidthnull
createCaptionsWhen true, automatic mode wraps outputted tags in a tag with a whose text is a copy of the image's title attribute. This makes generating captions from markdown possible.false
resizeOriginalWhen true, the original image will be resized.true
cropPositionSpecifies the default crop position for Sharp to use when cropping. Can be overridden on shortcodegravity.centre
dirs.inputPath to input directory./src
dirs.outputPath to output directory./dist

Using the shortcode

The shortcode syntax is:

{% srcset image, alt, className, width, height, sizes, cropPosition %}

AttributeDetails
imagePath to input image
altImage alt text
classNameDesired class of output image
widthImage width (used to establish image aspect ratio)
heightImage height (used to establish image aspect ratio)
sizesImage sizes attribute, e.g. "(min-width: 600px) 50vw, 100vw"
cropPositionSharp crop position, e.g. gravity.centre
lazyloadSet this to be true to lazyload images.
0.5.0

2 years ago

0.2.1

2 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago