An open API service indexing awesome lists of open source software.

https://github.com/enjikaka/lume_plugin_squoosh

Plugin for static site generator Lume to resize and encode images with Squoosh.
https://github.com/enjikaka/lume_plugin_squoosh

deno lume squoosh static-site-generator

Last synced: 2 months ago
JSON representation

Plugin for static site generator Lume to resize and encode images with Squoosh.

Awesome Lists containing this project

README

          

# lume_plugin_squoosh

A plugin for Lume to use Squoosh CLI for handling images for your static site.

Requires that you have Node installed for running Squoosh CLI via npx.

## Usage

In your Lume `_config.js` file import and add this plugin like so:

```js
import squoosh from "https://deno.land/x/lume_plugin_squoosh@v0.0.9/index.ts";

const site = lume();

site.use(squoosh());
```

The squoosh method takes an optional parameter than is an array of formats to generate. If not set, it default to generating WEBP and AVIF.

Example of editing output formats:

```js
import squoosh from "https://deno.land/x/lume_plugin_squoosh@v0.0.9/index.ts";

const site = lume();

site.use(squoosh(['jxl', 'wp2']));
```

Put your images like normal in the img directory and reference them in your post with an HTML-image tag and specify desired sizes with the `width` and `data-srcset` attribute.

```html
Förodlingsstation med IKEA Hyllis
```

Make sure that `width` is the same as the actual final element with on your page, for loading performance reasons. `width="600"` and `data-srcset="1x, 1.5x, 2x"` above instructs the plugin to render sizes at 600px, 900px and 1200px.

The plugin will transform the `` tag into a `` tag with the desired formats from _config.js (or the default ones if not set) and with all the sizes:

```html



Förodlingsstation med IKEA Hyllis

```

## Real world use case

If you want a real world use-case example this plugin is used for my farm blog.

Live site: https://barlingshult.se

Source: https://github.com/enjikaka/barlingshult