Skip to content

Commit 127f232

Browse files
kripodwardpeet
authored andcommitted
feat(gatsby-plugin-manifest): add icon_options as an option to support the purpose property (#12794)
<!-- Have any questions? Check out the contributing docs at https://gatsby.dev/contribute, or ask in this Pull Request and a Gatsby maintainer will be happy to help :) --> ## Description Adds an option to specify PWA icon options, e.g. [`purpose`](https://www.w3.org/TR/appmanifest/#purpose-member). ## Related Issues Resolves #12793
1 parent e30d264 commit 127f232

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/gatsby-plugin-manifest/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,36 @@ module.exports = {
188188
}
189189
```
190190

191+
## Custom icon options
192+
193+
In order to specify manifest options merged with each item of the `icons` array, `icon_options` may be used as follows:
194+
195+
```js
196+
// in gatsby-config.js
197+
module.exports = {
198+
plugins: [
199+
{
200+
resolve: `gatsby-plugin-manifest`,
201+
options: {
202+
name: `GatsbyJS`,
203+
short_name: `GatsbyJS`,
204+
start_url: `/`,
205+
background_color: `#f7f0eb`,
206+
theme_color: `#a2466c`,
207+
display: `standalone`,
208+
icon: `src/images/icon.png`, // This path is relative to the root of the site.
209+
icon_options: {
210+
// For all the options available, please see:
211+
// https://developer.mozilla.org/en-US/docs/Web/Manifest
212+
// https://w3c.github.io/manifest/#purpose-member
213+
purpose: `maskable`,
214+
},
215+
},
216+
},
217+
],
218+
}
219+
```
220+
191221
## Legacy option
192222

193223
iOS 11.3 added support for service workers but not the complete webmanifest spec. Therefore iOS won't recognize the icons defined in the webmanifest and the creation of `apple-touch-icon` links in `<head>` is needed. This plugin creates them by default. If you don't want those icons to be generated you can set the `legacy` option to `false` in plugin configuration:

packages/gatsby-plugin-manifest/src/gatsby-node.js

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ exports.onPostBootstrap = async (args, pluginOptions) => {
5454
manifest.icons = defaultIcons
5555
}
5656

57+
// Specify extra options for each icon (if requested).
58+
manifest.icons.forEach(icon => {
59+
Object.assign(icon, pluginOptions.icon_options)
60+
})
61+
5762
// Determine destination path for icons.
5863
const iconPath = path.join(`public`, path.dirname(manifest.icons[0].src))
5964

0 commit comments

Comments
 (0)