Skip to content

Commit

Permalink
feat(gatsby-source-wordpress): generate webp images (#30896)
Browse files Browse the repository at this point in the history
* feat(gatsby-source-wordpress): generate webp images

* feat(gatsby-source-wordpress): add html.generateWebpImages plugin option

* feat(gatsby-source-wordpress): add docs for html.generateWebpImages plugin option

* Update declare-plugin-options-schema.ts

* Update plugin-options.md

Co-authored-by: Tyler Barnes <tylerdbarnes@gmail.com>
  • Loading branch information
vi-nastya and TylerBarnes committed Aug 6, 2021
1 parent 59a6287 commit fcd0b44
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/gatsby-source-wordpress/docs/plugin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- [html.fallbackImageMaxWidth](#htmlfallbackimagemaxwidth)
- [html.imageQuality](#htmlimagequality)
- [html.createStaticFiles](#htmlcreatestaticfiles)
- [html.generateWebpImages](#htmlgeneratewebpimages)
- [type](#type)
- [type.\_\_all](#type__all)
- [type.\_\_all.where](#type__allwhere)
Expand Down Expand Up @@ -960,6 +961,26 @@ When this is true, any url's which are wrapped in "", '', or () and which contai

```

### html.generateWebpImages

When this is true, .webp images will be generated for images in html fields in addition to the images gatsby-image normally generates.

**Field type**: `Boolean`

**Default value**: `false`

```js
{
resolve: `gatsby-source-wordpress`,
options: {
html: {
generateWebpImages: false,
},
},
}

```

## type

Options related to specific types in the remote schema.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,19 @@ When using this option, be sure to gitignore the wordpress-cache directory in th
},
`),
}),
generateWebpImages: Joi.boolean()
.default(false)
.allow(null)
.description(
`When this is true, .webp images will be generated for images in html fields in addition to the images gatsby-image normally generates.`
)
.meta({
example: wrapOptions(`
html: {
generateWebpImages: false,
},
`),
}),
})
.description(`Options related to html field processing.`)
.meta({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,22 @@ const replaceNodeHtmlImages = async ({
reporter,
cache,
})

if (pluginOptions?.html?.generateWebpImages) {
const webpResult = await fluid({
file: fileNode,
args: {
maxWidth,
quality,
pathPrefix,
toFormat: `WEBP`,
},
reporter,
cache,
})

fluidResult.srcSetWebp = webpResult.srcSet
}
} catch (e) {
reporter.error(e)
reporter.warn(
Expand Down

0 comments on commit fcd0b44

Please sign in to comment.