Skip to content

Commit f55259c

Browse files
authored
Merge pull request #8 from posthtml/milestone-1.4.0
Milestone 1.4.0
2 parents 58e2a99 + cc8f68f commit f55259c

8 files changed

Lines changed: 155 additions & 103 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ After:
4949

5050
#### `replaceExtension`
5151

52-
Type: `boolean`
52+
Type: `Boolean`
5353
Default: `false`
5454
Description: *Replace the extension of the source image with .webp instead of appending .webp to the original filename*
5555
Example: `image.jpg => image.webp (instead of image.jpg.webp)`
5656

57+
#### `classIgnore`
58+
59+
Type: `Array<string>`
60+
Default: `[]`
61+
Description: *list of classes for which the transformation will be ignored*
62+
Example: `image.jpg => image.webp (instead of image.jpg.webp)`
63+
5764
### License [MIT](LICENSE)
5865

5966
[npm]: https://img.shields.io/npm/v/posthtml-webp.svg

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
## 1.4.0 (2019-10-22)
2+
3+
* docs: for ignore ([15953c7](https://github.com/posthtml/posthtml-webp/commit/15953c7))
4+
* feat: ignore, close #21 ([735ed05](https://github.com/posthtml/posthtml-webp/commit/735ed05)), closes [#21](https://github.com/posthtml/posthtml-webp/issues/21)
5+
* test: for ignore, issue #21 ([4fa4423](https://github.com/posthtml/posthtml-webp/commit/4fa4423)), closes [#21](https://github.com/posthtml/posthtml-webp/issues/21)
6+
* perf: process ([433d79c](https://github.com/posthtml/posthtml-webp/commit/433d79c))
7+
* build: update depDev ([c6073ba](https://github.com/posthtml/posthtml-webp/commit/c6073ba))
8+
9+
10+
111
## 1.3.0 (2019-09-26)
212

13+
* chore: v1.3.0 ([b7c29c6](https://github.com/posthtml/posthtml-webp/commit/b7c29c6))
14+
* build: update changelog ([a968946](https://github.com/posthtml/posthtml-webp/commit/a968946))
315
* feat: multi srcset, close #5 ([b31efc6](https://github.com/posthtml/posthtml-webp/commit/b31efc6)), closes [#5](https://github.com/posthtml/posthtml-webp/issues/5)
416
* docs: simple update ([cc7079e](https://github.com/posthtml/posthtml-webp/commit/cc7079e))
517
* test: for issue #5 ([9b63e67](https://github.com/posthtml/posthtml-webp/commit/9b63e67)), closes [#5](https://github.com/posthtml/posthtml-webp/issues/5)

lib/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@ module.exports = function (options) {
55
options = {}
66
}
77

8+
if (!options.classIgnore) {
9+
options.classIgnore = []
10+
}
11+
812
if (options.replaceExtension === undefined) {
913
options.replaceExtension = false
1014
}
1115

1216
return function posthtmlWebp (tree) {
13-
tree.match({ tag: 'img' }, function (imgNode) {
14-
if (imgNode.skip) return imgNode
15-
return getPicture(imgNode, options)
16-
})
17-
18-
tree.match({ tag: 'amp-img' }, function (imgNode) {
17+
tree.match([{ tag: 'img' }, { tag: 'amp-img' }], function (imgNode) {
1918
if (imgNode.skip) return imgNode
20-
return getAmpPicture(imgNode, options)
19+
var classes = imgNode.attrs && imgNode.attrs.class && (imgNode.attrs.class.split(' ') || [])
20+
var isIgnore = options.classIgnore.filter(className => classes.includes(className)).length > 0
21+
if (isIgnore) return imgNode
22+
switch (imgNode.tag) {
23+
case 'amp-img':
24+
return getAmpPicture(imgNode, options)
25+
default:
26+
return getPicture(imgNode, options)
27+
}
2128
})
2229

2330
return tree

0 commit comments

Comments
 (0)