Skip to content

Commit 7802470

Browse files
DZuz14pieh
authored andcommitted
feat(gatsby-plugin-manifest): don't output theme-color meta tag if it's not defiened (#10069)
Not really sure how I go about submitting a PR here. This addition references issue #9977 Any guidance would be greatly appreciated.
1 parent 73167e3 commit 7802470

File tree

4 files changed

+88
-58
lines changed

4 files changed

+88
-58
lines changed

packages/gatsby-plugin-manifest/src/__tests__/__snapshots__/gatsby-ssr.js.snap

+13
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,16 @@ Array [
100100
/>,
101101
]
102102
`;
103+
104+
exports[`gatsby-plugin-manifest Does not add a "theme_color" meta tag to head if "theme_color" option is not provided or is an empty string 1`] = `
105+
Array [
106+
<link
107+
href="/icons/icon-48x48.png"
108+
rel="shortcut icon"
109+
/>,
110+
<link
111+
href="/manifest.webmanifest"
112+
rel="manifest"
113+
/>,
114+
]
115+
`;

packages/gatsby-plugin-manifest/src/__tests__/gatsby-ssr.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe(`gatsby-plugin-manifest`, () => {
1919
expect(headComponents).toMatchSnapshot()
2020
})
2121

22+
it(`Does not add a "theme_color" meta tag to head if "theme_color" option is not provided or is an empty string`, () => {
23+
onRenderBody(ssrArgs, { icon: true })
24+
expect(headComponents).toMatchSnapshot()
25+
})
26+
2227
describe(`Creates legacy apple touch links if opted in`, () => {
2328
it(`Using default set of icons`, () => {
2429
onRenderBody(ssrArgs, {

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

+33-21
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,58 @@ import { withPrefix } from "gatsby"
33
import { defaultIcons } from "./common.js"
44

55
exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
6+
// We use this to build a final array to pass as the argument to setHeadComponents at the end of onRenderBody.
7+
let headComponents = []
8+
69
const icons = pluginOptions.icons || defaultIcons
710

811
// If icons were generated, also add a favicon link.
912
if (pluginOptions.icon) {
1013
let favicon = icons && icons.length ? icons[0].src : null
1114

1215
if (favicon) {
13-
setHeadComponents([
16+
headComponents.push(
1417
<link
1518
key={`gatsby-plugin-manifest-icon-link`}
1619
rel="shortcut icon"
1720
href={withPrefix(favicon)}
18-
/>,
19-
])
21+
/>
22+
)
2023
}
2124
}
2225

23-
setHeadComponents([
26+
// Add manifest link tag.
27+
headComponents.push(
2428
<link
2529
key={`gatsby-plugin-manifest-link`}
2630
rel="manifest"
2731
href={withPrefix(`/manifest.webmanifest`)}
28-
/>,
29-
<meta
30-
key={`gatsby-plugin-manifest-meta`}
31-
name="theme-color"
32-
content={pluginOptions.theme_color}
33-
/>,
34-
])
32+
/>
33+
)
3534

36-
if (pluginOptions.legacy) {
37-
setHeadComponents(
38-
icons.map(icon => (
39-
<link
40-
key={`gatsby-plugin-manifest-apple-touch-icon-${icon.sizes}`}
41-
rel="apple-touch-icon"
42-
sizes={icon.sizes}
43-
href={withPrefix(`${icon.src}`)}
44-
/>
45-
))
35+
// The user has an option to opt out of the theme_color meta tag being inserted into the head.
36+
if (pluginOptions.theme_color) {
37+
headComponents.push(
38+
<meta
39+
key={`gatsby-plugin-manifest-meta`}
40+
name="theme-color"
41+
content={pluginOptions.theme_color}
42+
/>
4643
)
4744
}
45+
46+
if (pluginOptions.legacy) {
47+
const iconLinkTags = icons.map(icon => (
48+
<link
49+
key={`gatsby-plugin-manifest-apple-touch-icon-${icon.sizes}`}
50+
rel="apple-touch-icon"
51+
sizes={icon.sizes}
52+
href={withPrefix(`${icon.src}`)}
53+
/>
54+
))
55+
56+
headComponents = [...headComponents, ...iconLinkTags]
57+
}
58+
59+
setHeadComponents(headComponents)
4860
}
+37-37
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
## gatsby-source-faker
2-
3-
This is a plugin that allows you to use [faker.js](https://github.com/marak/Faker.js/) to generate fake data for gatsby sites. This could come in handy for creating example sites, documentation, or just to experiment with Gatsby.js
4-
5-
### To use it
6-
7-
Install `gatsby-source-faker`
8-
9-
```
10-
npm install --save gatsby-source-faker
11-
```
12-
13-
or
14-
15-
```
16-
npm install gatsby-source-faker
17-
```
18-
19-
Add `gatsby-source-faker` to the `gatsby-config.js` as follows
20-
21-
```javascript
22-
plugins: [
23-
{
24-
resolve: `gatsby-source-faker`,
25-
// derive schema from faker's options
26-
options: {
27-
schema: {
28-
name: ["firstName", "lastName"],
29-
},
30-
count: 3, // how many fake objects you need
31-
type: "NameData", // Name of the graphql query node
32-
},
33-
},
34-
]
35-
```
36-
37-
Example: [Using Faker](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-faker)
1+
## gatsby-source-faker
2+
3+
This is a plugin that allows you to use [faker.js](https://github.com/marak/Faker.js/) to generate fake data for gatsby sites. This could come in handy for creating example sites, documentation, or just to experiment with Gatsby.js
4+
5+
### To use it
6+
7+
Install `gatsby-source-faker`
8+
9+
```
10+
npm install --save gatsby-source-faker
11+
```
12+
13+
or
14+
15+
```
16+
npm install gatsby-source-faker
17+
```
18+
19+
Add `gatsby-source-faker` to the `gatsby-config.js` as follows
20+
21+
```javascript
22+
plugins: [
23+
{
24+
resolve: `gatsby-source-faker`,
25+
// derive schema from faker's options
26+
options: {
27+
schema: {
28+
name: ["firstName", "lastName"],
29+
},
30+
count: 3, // how many fake objects you need
31+
type: "NameData", // Name of the graphql query node
32+
},
33+
},
34+
]
35+
```
36+
37+
Example: [Using Faker](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-faker)

0 commit comments

Comments
 (0)