0.5.0 • Published 3 years ago
eleventy-plugin-srcset v0.5.0
This Eleventy plugin generates responsive image markup along with the corresponding image files.
It can be used in two ways:
- The manually inserted shortcode, {% srcset %}
- 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.
| Value | Details | Default |
|---|---|---|
| autoselector | Specifies 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' |
| srcsetWidths | An array of the breakpoint widths used to generate images | 320, 480, 640, 960, 1280, 1600 |
| fallbackWidth | The width for the fallback 'src' image | 640 |
| fallbackHeight | The height for the fallback 'src' image, when null the image will be automatic based on the aspect ratio and fallbackWidth | null |
| createCaptions | When 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 |
| resizeOriginal | When true, the original image will be resized. | true |
| cropPosition | Specifies the default crop position for Sharp to use when cropping. Can be overridden on shortcode | gravity.centre |
| dirs.input | Path to input directory | ./src |
| dirs.output | Path to output directory | ./dist |
Using the shortcode
The shortcode syntax is:
{% srcset image, alt, className, width, height, sizes, cropPosition %}
| Attribute | Details |
|---|---|
| image | Path to input image |
| alt | Image alt text |
| className | Desired class of output image |
| width | Image width (used to establish image aspect ratio) |
| height | Image height (used to establish image aspect ratio) |
| sizes | Image sizes attribute, e.g. "(min-width: 600px) 50vw, 100vw" |
| cropPosition | Sharp crop position, e.g. gravity.centre |
| lazyload | Set this to be true to lazyload images. |
0.5.0
3 years ago
0.2.1
4 years ago
0.4.0
5 years ago
0.3.0
5 years ago
0.2.0
5 years ago
0.1.19
5 years ago
0.1.18
5 years ago
0.1.17
5 years ago
0.1.15
6 years ago
0.1.14
6 years ago
0.1.12
6 years ago
0.1.13
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.9
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago