1.2.0 • Published 10 months ago

rehype-thumbhash v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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="data:image/png;base64,iVBORw0KGgoAAA..."
    />
  </body>
</html>
1.2.0

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago