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

metalsmith-picset-handlebars-helper

v0.0.2

Published

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

Downloads

2

Readme

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

  • You have a handlebars package installed somewhere either directly or as a sub-dependency (We use that same version / install)
  • /img/picset/anthony_80webp_90jpg_2000,1000,500w.jpg as a 2000px wide 90% quality photo
  • metalsmith-picset-generate is used earlier in your metalsmith pipeline

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="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

  • You have a handlebars package installed somewhere either directly or as a sub-dependency (We use that same version / install)

Metalsmith options object

{
	path: 'img/picset'
}

path

  • Relative to Metalsmith source folder
  • Default: img/picset/

Helper use

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

  • Parameter 1 (NAME): Image source name
  • Parameter 2 (DEFAULT_WIDTH): Default width
  • Parameter 3 (SIZES): Optional sizes
  • Parameter 4 (ALT): Optional alt tag

Generates <picture> elements with:

  • srcset parameters that include all files found following metalsmith-picset-generate's naming convention
  • <source> with .webp type in srcset
  • <img> with:
  • srcset with file type of .jpg, .png, or .svg as a fallback
  • src at default width and same file type as it's srcset
  • sizes attribute as specified duplicated on both the <source> and <img ...> tags

Background info

Philosophy

  • Convention over Configuration
  • Simple case of resizing only (artistic decisions not thought through for this)
  • Give the browser all availble choices
  • Reduce bandwidth bloat and keep high quality:
  1. .webp is first choice
  2. Responsive size is first choice
  3. Always give fallbacks
  • Standards based (Using <picture> with inner <img src="..."> fallback)

Inspiration

Implementation

  • Implemented on Node v6.9.1, untested in other versions
  • Doesn't install handlebars, as assumes you have it in your MetalSmith install and we want to use that same version