Skip to content

Commit 7e0a153

Browse files
committed
feat: add documentation to the README.md file
1 parent 1ee3f2b commit 7e0a153

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,100 @@
22

33
[![](/github-banner.jpg)](https://www.zapal.tech)
44

5+
Turbocharge your website performance by creating ultralight image placeholders, resulting in a smoother user experience.
6+
7+
### 📋 Requirements
8+
9+
- Payload version `1.7.2` or higher is required (version `2.0.0` or higher is recommended)
10+
11+
## 🚀 Getting started
12+
13+
Instal the package with `yarn add @zapal/payload-blurhash-plugin` or `npm install @zapal/payload-blurhash-plugin`
14+
15+
Now setup the plugin within your `payload.config.ts` file as follows:
16+
17+
```ts
18+
import { buildConfig } from 'payload/config';
19+
20+
import { blurHash } from '@zapal/payload-blurhash-plugin';
21+
import path from 'path';
22+
23+
/* ... */
24+
25+
export default buildConfig({
26+
plugins: [
27+
blurHash({
28+
collections: ['team-photos-collection', 'blog-images-collection'],
29+
}),
30+
],
31+
/* ... */
32+
});
33+
```
34+
35+
The plugin will generate a readonly `blurhash` field for each image uploaded to the specified collections. Generation
36+
for `imageSizes` are not supported yet (but it's in progress).
37+
38+
### 🎛️ Conditionally enabling/disabling
39+
40+
The proper way to conditionally enable/disable this plugin is to use the `enabled` property.
41+
42+
```ts
43+
blurHash({
44+
enabled: process.env.ENABLE_BLURHASH_PLUGIN === 'true',
45+
collections: ['team-photos-collection', 'blog-images-collection'],
46+
}),
47+
```
48+
49+
## ⚙️ Plugin options
50+
51+
This plugin is configurable to work across upload-enabled Payload collections. A `*` denotes that the property is
52+
required.
53+
54+
| Option | Type | Description |
55+
| -------------------- | -------- | ----------------------------------------------------------------------------- |
56+
| **`collections`** \* | string[] | Array of upload-enabled collections' slugs you want to enable the plugin for. |
57+
| `enabled` | boolean | Conditionally enable/disable plugin. Default: true. |
58+
| `width` | number | Width to resize the image before computing the blurhash. Default: 32. |
59+
| `height` | number | Height to resize the image before computing the blurhash. Default: 32. |
60+
| `componentX` | number | X component count to pass to the blurhash encoder. Default: 3. |
61+
| `componentY` | number | Y component count to pass to the blurhash encoder. Default: 3. |
62+
63+
See more information about the `width`, `height`, `componentX`, `componentY` options and BlurHash encoder
64+
[here](https://github.com/woltapp/blurhash#good-questions).
65+
66+
## 💻 Local development
67+
68+
You can find the source code in the `src` directory. For development purposes, you can use the `dev` directory with all
69+
the necessary files to test the plugin in a Payload project. Also we are strongly recommending to use your IDE debugger
70+
instead of `console.log` statements.
71+
72+
You need to follow these steps to start developing and testing the plugin locally:
73+
74+
1. Go to `dev` directory (`cd dev`)
75+
2. Create `.env` file (`cp .env.example .env`)
76+
3. Setup environment variables in `.env` file
77+
4. Install dependencies (`npm i`)
78+
5. Run the project (`npm run dev`)
79+
80+
And you are ready to go!
81+
82+
## 🤝 Contributing
83+
84+
We are open to, and grateful for, any contributions made by the community.
85+
86+
We are planning to add more features to this plugin in the future. If you have any ideas, create an issue to discuss it.
87+
88+
Next steps (v1):
89+
90+
- [ ] Optional blurhash generation for `imageSizes` (in progress)
91+
- [ ] Custom field name support
92+
- [ ] Unit tests
93+
- [ ] Code refactoring
94+
95+
Next steps (v2):
96+
97+
- [ ] Custom options for each collection
98+
599
## 🛡️ License
6100

7101
This project is licensed under the [MIT License](/LICENSE)

github-banner.jpg

20.8 KB
Loading

0 commit comments

Comments
 (0)