Skip to content

Commit 40f9b5a

Browse files
committed
docs: ✏️ Add convertFormat to the configuration page
1 parent 457c453 commit 40f9b5a

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

docs/docs/configuration.md

+27
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,30 @@ Specifically, include the name, width, quality, and extension in the return valu
9999

100100
You can set optimization options for each extension.
101101
Please refer to the official sharp documentation for more information.
102+
103+
### `convertFormat`
104+
105+
**Available from ver. 1.2.0.**
106+
107+
- Type: Array<Array<Format, Format>>
108+
Format → "jpeg" | "jpg" | "png" | "webp" | "avif"
109+
110+
It allows you to convert images from any extension to another extension.
111+
112+
e.g.
113+
114+
```js
115+
const config = {
116+
convertFormat: [
117+
['png', 'webp'],
118+
['jpg', 'avif'],
119+
],
120+
}
121+
```
122+
123+
```jsx
124+
<Image src="/img.png" width={1280} height={640} alt="" />
125+
<Image src="/img.jpg" width={1280} height={640} alt="" />
126+
```
127+
128+
The original image will be kept, `img.png` will be converted to webp format and `img.jpg` will be converted to avif format and output to the directory.

docs/docs/planned-features.md

-12
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ description: This page is to introduce examples of use.
99

1010
We are planning the ability to save external images locally when they are specified.
1111

12-
## Convert to specified format
13-
14-
We plan to have the ability to convert to a specified format.
15-
16-
For example, to convert to webp, the following configuration is used.
17-
18-
```js title="export-images.config.js"
19-
module.exports = {
20-
convertFormat: 'webp',
21-
}
22-
```
23-
2412
:::caution
2513
This API is in the planning stage and is subject to change in practice.
2614
:::

src/utils/getConfig.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type Config = {
4343
* You can set optimization options for each extension.
4444
* Please refer to the official sharp documentation for more information.
4545
*
46-
* @type {{ png?: import('sharp').PngOptions, jpg?: import('sharp').JpegOptions, webp?: import('sharp').WebpOptions, avif?: import('sharp').AvifOptions } }}
46+
* @type {{ png?: PngOptions, jpg?: JpegOptions, webp?: WebpOptions, avif?: AvifOptions } }}
4747
*/
4848
sharpOptions?: {
4949
png?: PngOptions
@@ -53,6 +53,8 @@ export type Config = {
5353
}
5454
/**
5555
* It allows you to convert images from any extension to another extension.
56+
*
57+
* @type {[beforeConvert: AllowedFormat, afterConvert: AllowedFormat][]}
5658
*/
5759
convertFormat?: [beforeConvert: AllowedFormat, afterConvert: AllowedFormat][]
5860
}

0 commit comments

Comments
 (0)