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

hexo-filter-lqip

v1.5.0

Published

A Hexo plugins which helps to introduce low quality image placeholders to the theme

Downloads

11

Readme

hexo-filter-lqip

A Hexo plugins which helps to introduce low quality image placeholders to the theme

Installation

npm i hexo-filter-lqip --save

Usage

Install this plugin for the theme and use the view helper to render a placeholder.

lqipFor view helper

lqipFor(path_to_asset, options)
  • String *path_to_asset - a path to the image
  • Object options
    • String [type] - a type of placeholder, see the list of available types, defaults to the default_type as configured

Returns a CSS value for background-image property, which is a simplified version of the original image.

Example for EJS

<div
  style="background-image: <%- lqip_for('/content/my-photo.jpg') %>"
></div>

Front-end integration

To make it work as a real placeholder, there must be a piece of JavaScript code, which will eventually replace the placeholder with the original image. It can be done by adding a data attribute with the original image path:

<div
  style="background-image: <%- lqip_for('/content/my-photo.jpg') %>"
  data-lazy-src="/content/my-photo.jpg"
></div>

and replacing the background-image CSS property with the original image once it's loaded:

(function () {
  var lazyImages = document.querySelectorAll('[data-lazy-src]')

  lazyImages.forEach(function (img) {
    var url = img.dataset.lazySrc
    var image = new Image()
    image.onload = function () {
      img.style.backgroundImage = 'url(' + url + ')'
    }
    image.src = url
  })
})()

For even more improvement, the script could load only images that are visible on the screen.

Available types

Potrace

Type name: potrace

Uses the posterize function from potrace to generate simplified SVG version of the image. The output is optimized with SVGO and inlined.

Color

Type name: color

Plain background, the dominant color extracted from the image.

Configuration

Put your configuration in the theme _config.yml under lqip key. You can also use the overriding theme config feature of Hexo. Available options are the following:

cache

Defaults to 'lqip-cache.json'. Could be a string with a file name of the cache. You can also set to false to disable caching.

Ideally, the cache file should not be checked in into repository.

priority

The priority of the after_generate filter. Defaults to 10. You can find more information about priority in Filter documentation.

default_type

Defaults to potrace. Use this type if not specified as a param to lqip_for helper.

potrace

Configuration specific to potrace type. All keys except canvas_size are passed to the posterize function of potrace

canvas_size: {width:, height:}

Before the image is passed to potrace, it's resized to this size.

Example configuration:

lqip:
  default_type: potrace
  potrace:
    canvas_size:
      width: 140
    steps: 2
    color: '#dedede'
    background: transparent

Debugging

If something goes wrong, use --debug option to get all information about the generating of the blog and extra information about low-quality image placeholders processing.

hexo generate --debug

After changing parameters of placeholder it may be required to clean cache, by removing the cache file manually or with:

hexo clean

Example project

You can see it put together in the hexo-lqip-example repository.

Out there in the wild

Inspirations