Skip to content

rehype plugin to set the thumbhash of local images to the data-thumbhash img attribute

License

Notifications You must be signed in to change notification settings

AlphaJack/rehype-thumbhash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rehype-thumbhash

A rehype plugin that generates small thumbnails using from local images using sharp and thumbhash, and adds stores as data-thumbhash attributes.
These thumbnails can then be used by client-side libraries such as lazysizes.

Install

npm install rehype-thumbhash

Options

Optional:

  • dir: prefix to local images
  • format: thumbhash format, either "hash" or "url". Defaults to "hash".
  • originalAttribute: attribute where to store the original "src". Defaults to "src".
  • thumbhashAttribute: attribute where to store the thumbhash image. Defaults to "data-thumbhash".

Usage

import { rehype } from "rehype";
import rehypeThumbhash from "rehypeThumbhash";

rehype()
  .use(rehypeThumbhash, { dir: "./" })
  .process('<img src="example.jpg">', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Expected output:

<html>
  <head></head>
  <body>
    <img
      src="example.jpg"
      data-thumbhash="ZhgODYKHh3l/ioh0d5hohkVtEOYG"
    />
  </body>
</html>

About

rehype plugin to set the thumbhash of local images to the data-thumbhash img attribute

Topics

Resources

License

Stars

Watchers

Forks