AnthonyAstige / metalsmith-picset-handlebars-helper

Uses generated responsive image resolutions :: Those generated by metalsmith-picset-generate display in browser via a <picture> element
0 stars 2 forks source link

Uses picture sets generated by metalsmith-picset-generate to give browsers choice

Example use

Add to your pipeline like

npm i metalsmith-picset-handlebars-helper --save
const picsetHandlearsHelper = require('metalsmith-picset-handlebars-helper')
Metalsmith(__dirname)
    ...
    .use(picsetHandlearsHelper())
    ...

Assume

Then use the handlebars helper like {{{picset "anthony" 500}}} to output something like

<picture>
    <source type="image/webp"
        srcset="img/srcsets/anthony-2000.webp 2000w, img/srcsets/anthony-1000.webp 1000w, img/srcsets/anthony-500.webp 500w" sizes="100vw" />
    <img src="https://github.com/AnthonyAstige/metalsmith-picset-handlebars-helper/raw/master/img/srcsets/anthony-500.jpg"
        srcset="img/srcsets/anthony-2000.jpg 2000w, img/srcsets/anthony-1000.jpg 1000w, img/srcsets/anthony-500.jpg 500w" sizes="100vw" />
</picture>

Specification

Metalsmith requirements

Metalsmith options object

{
    path: 'img/picset'
}

path

Helper use

Like {{{picset NAME DEFAULT_WIDTH SIZES ALT}}}

Generates <picture> elements with:

Background info

Philosophy

Inspiration

Implementation