Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mattstein/astro-imgproxy

Astro imgproxy plugin.
https://github.com/mattstein/astro-imgproxy

Last synced: about 2 months ago
JSON representation

Astro imgproxy plugin.

Awesome Lists containing this project

README

        

# Astro imgproxy Plugin

A plugin for adding [imgproxy](https://github.com/imgproxy/imgproxy) support to an Astro project in two parts:

1. Remark plugin for transforming Markdown image URLs.
2. Utilities for prepping imgproxy URLs in other contexts like Astro components.

## Setup

**`.env`**:

```shell
IMGPROXY_KEY="my-key"
IMGPROXY_SALT="my-salt"
IMGPROXY_BASE_URL="https://my-improxy-instance.foo"
```

**`astro.config.mjs`**:

```js
import imgproxy from "astro-imgproxy/remark";

export default defineConfig({
// ...
markdown: {
// ...
remarkPlugins: [imgproxy],
// ...
},
});
```

## Usage

By default, the remark plugin doesn’t change anything.

To use it, you’ll need to add `?imgproxy` params to any absolute image URLs you’d like to transform.

The URL param’s argument should be a comma-separated list of imgproxy [processing options](https://docs.imgproxy.net/generating_the_url?id=processing-options).

Check out the tests for example input and output.

## Examples

### Markdown

Markdown image format:

```md
![](https://my-images.foo/original.png?imgproxy=s:2400)
```

Since you can use HTML in Markdown, the plugin should also grab valid `src` and `srcset` references, too:

```html



```

### Elsewhere

If you need to transform a URL in an Astro component or some other place on your site, you can use `isImgproxyUrl` to test whether a given image URL looks like it should be transformed for imgproxy, and `transformUrl` to transform it.

```js
import { isImgproxyUrl, transformUrl } from "astro-imgproxy";

// ...

if (isImgproxyUrl(myUrl)) {
const transformed = transformUrl(myUrl);
}
```