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

lqip-pug

v1.0.2

Published

lqip for pug based static projects

Downloads

3

Readme

lqip-pug

npm version JavaScript Style Guide

My take on low quality image placehoder for pug static builds

The basic idea implies combining this with something like lazysizes to have everything lazy loaded while giving something to see to the user while that loads.

Live Demo

Example

Setup

The main idea is to abstract everything in a mixin for ease of use. Here are shown the defaults the component has:

gulpfile.js

const gulp = require('gulp')
const pug = require('gulp-pug')

const BlurryPug = require('lqip-pug')
const blurry = new BlurryPug({
  // directory where your source images live must be an absolute path
  baseDir: process.cwd(),
  // compiled blurry image width size in pixels
  size: 16,
  // the compiled path of the image aka where the hosted real image lives
  compiledPath: 'img',
  // a function that will render the template for your mixins
  template: (presrc, src) => `<img src="${presrc}" data-src="${src}" class="lazyload" />`
})

gulp.task('pug', () =>
  gulp.src('./*/**.pug')
  .pipe(pug({
    locals: {blur: name => blurry.blur(name)}
  }))
  .pipe(gulp.dest('./public'))
)

Now on your pug files create a mixin like this:

mixins.pug

mixin img(name)
  !=blur(name)

and use it like this:

index.pug

+img('tenis.jpg')

You'll get something like this after compile:

<img src="data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAALABADASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAwQG/8QAIxAAAgECBgIDAAAAAAAAAAAAAQMCBREABAYHEkEhcTEyYf/EABUBAQEAAAAAAAAAAAAAAAAAAAQF/8QAHREAAQQCAwAAAAAAAAAAAAAAAQADBBECBRIhsf/aAAwDAQACEQMRAD8AfcbVdOrdDqun4LcMxMcDKwKyYzBIuDcX4kXxrdq8i6j7f0XKOVJDFptOB+ORJJ/D5JxdHLIU2bVIVBrPvOMAJS9nvDwbNRJXIxPdu/eAYyyOiLV2TpW3BbR4+L//2Q==" data-src="img/tenis.jpg" class="lazyload" />

Smile you have made your site much more performant.

Credits

  • lqip-loader for the inspiration
  • Example picture by Ben O'Sullivan on Unsplash