7
7
[ ![ Standard Code Style] [ style ]] [ style-url ]
8
8
[ ![ Chat] [ chat ]] [ chat-badge ]
9
9
10
- This plugin add webp supporting in your html.
10
+ This plugin add webp supporting in your html. Also supports [ ` <amp-img> ` ] ( https://amp.dev/documentation/components/amp-img/ )
11
+
12
+ ## Install
13
+ ``` bash
14
+ $ npm i posthtml posthtml-webp
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ``` js
20
+ const fs = require (' fs' );
21
+ const posthtml = require (' posthtml' );
22
+ const posthtmlWebp = require (' posthtml-webp' );
23
+
24
+ posthtml ()
25
+ .use (posthtmlWebp (/* Plugin options */ ))
26
+ .process (html/* , options */ )
27
+ .then (result => fs .writeFileSync (' ./after.html' , result .html ));
28
+ ```
29
+ ## Example
11
30
12
31
Before:
13
32
``` html
14
33
<img src =" image.jpg" >
34
+ <amp-img alt =" photo" width =" 550" height =" 368" layout =" responsive" src =" photo.png" ></amp-img >
15
35
```
16
36
17
37
After:
@@ -20,47 +40,19 @@ After:
20
40
<source type =" image/webp" srcset =" image.jpg.webp" >
21
41
<img src =" image.jpg" >
22
42
</picture >
23
- ```
24
-
25
- Also supports [ ` <amp-img> ` ] ( https://amp.dev/documentation/components/amp-img/ )
26
-
27
- Before:
28
- ``` html
29
- <amp-img alt =" photo" width =" 550" height =" 368" layout =" responsive" src =" photo.png" ></amp-img >
30
- ```
31
-
32
- After:
33
- ``` html
34
43
<amp-img alt =" photo" width =" 550" height =" 368" layout =" responsive" src =" photo.png.webp" >
35
44
<amp-img alt =" photo" width =" 550" height =" 368" layout =" responsive" src =" photo.png" fallback =" " ></amp-img >
36
45
</amp-img >
37
46
```
38
47
39
- ## Install
40
-
41
- > npm i posthtml posthtml-webp
48
+ ## Options
42
49
43
- ## Plugin options
44
- ` replaceExtension ` (boolean)
45
-
46
- ** Default:** false
47
-
48
- Replace the extension of the source image with .webp instead of appending .webp to the original filename
49
-
50
- ** Example** : image.jpg => image.webp (instead of image.jpg.webp)
51
-
52
- ## Usage
50
+ #### ` replaceExtension `
53
51
54
- ``` js
55
- const fs = require (' fs' );
56
- const posthtml = require (' posthtml' );
57
- const posthtmlWebp = require (' posthtml-webp' );
58
-
59
- posthtml ()
60
- .use (posthtmlWebp (/* Plugin options */ ))
61
- .process (html/* , options */ )
62
- .then (result => fs .writeFileSync (' ./after.html' , result .html ));
63
- ```
52
+ Type: ` boolean `
53
+ Default: ` false `
54
+ Description: * Replace the extension of the source image with .webp instead of appending .webp to the original filename*
55
+ Example: ` image.jpg => image.webp (instead of image.jpg.webp) `
64
56
65
57
### License [ MIT] ( LICENSE )
66
58
0 commit comments