Skip to content

Commit 9a04b8d

Browse files
committed
Publisher logo fix in JSON LD
1 parent f6afed0 commit 9a04b8d

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

gatsby-wordpress-theme-libre/src/components/meta/article-meta.js

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const capitalize = (str) => {
1212
}
1313
};
1414

15-
1615
const ArticleMeta = ({ data, amp, location }) => {
1716
const queryData = useStaticQuery(graphql`
1817
query {
@@ -64,12 +63,12 @@ const ArticleMeta = ({ data, amp, location }) => {
6463
: null;
6564

6665
const twitterImageUrl = feature_image
67-
? url.resolve(config.siteUrl, feature_image)
68-
: config.twitterCard.imageUrl
69-
? url.resolve(config.siteUrl, config.twitterCard.imageUrl)
70-
: config.coverUrl
71-
? url.resolve(config.siteUrl, config.coverUrl)
72-
: null;
66+
? url.resolve(config.siteUrl, feature_image)
67+
: config.twitterCard.imageUrl
68+
? url.resolve(config.siteUrl, config.twitterCard.imageUrl)
69+
: config.coverUrl
70+
? url.resolve(config.siteUrl, config.coverUrl)
71+
: null;
7372

7473
const author = data.author;
7574
const publicTags = _.map(data.tags, (tag) => tag.name);
@@ -94,12 +93,14 @@ const ArticleMeta = ({ data, amp, location }) => {
9493
const jsonLd = {
9594
"@context": `https://schema.org/`,
9695
"@type": `Article`,
97-
author: author ? {
98-
"@type": `Person`,
99-
name: author.name,
100-
image: undefined,
101-
sameAs: undefined,
102-
} : null,
96+
author: author
97+
? {
98+
"@type": `Person`,
99+
name: author.name,
100+
image: undefined,
101+
sameAs: undefined,
102+
}
103+
: null,
103104
keywords: publicTags.length ? publicTags.join(`, `) : undefined,
104105
headline: data.plainTitle || config.siteTitle,
105106
url: canonicalUrl,
@@ -116,12 +117,14 @@ const ArticleMeta = ({ data, amp, location }) => {
116117
publisher: {
117118
"@type": `Organization`,
118119
name: config.siteTitle,
119-
logo: {
120-
"@type": `ImageObject`,
121-
url: publisherLogo,
122-
width: 60,
123-
height: 60,
124-
},
120+
logo: publisherLogo
121+
? {
122+
"@type": `ImageObject`,
123+
url: publisherLogo,
124+
width: 60,
125+
height: 60,
126+
}
127+
: undefined,
125128
},
126129
description: data.plainExcerpt || config.siteDescription,
127130
mainEntityOfPage: {
@@ -132,7 +135,7 @@ const ArticleMeta = ({ data, amp, location }) => {
132135

133136
return (
134137
<>
135-
<Helmet htmlAttributes={{lang:queryData.site.siteMetadata.language}}>
138+
<Helmet htmlAttributes={{ lang: queryData.site.siteMetadata.language }}>
136139
<title>{capitalize(data.plainTitle)}</title>
137140
{!amp && <link rel="ampHtml" href={`${canonicalUrl}/amp`} />}
138141
<meta name="description" content={data.plainExcerpt} />
@@ -180,8 +183,12 @@ const ArticleMeta = ({ data, amp, location }) => {
180183
{twitterImageUrl && (
181184
<meta name="twitter:card" content="summary_large_image" />
182185
)}
183-
{twitterImageUrl && <meta name="twitter:image" content={twitterImageUrl} />}
184-
{facebookImageUrl && <meta property="og:image" content={facebookImageUrl} />}
186+
{twitterImageUrl && (
187+
<meta name="twitter:image" content={twitterImageUrl} />
188+
)}
189+
{facebookImageUrl && (
190+
<meta property="og:image" content={facebookImageUrl} />
191+
)}
185192
{config.twitterCard.username && (
186193
<meta name="twitter:site" content={config.twitterCard.username} />
187194
)}

gatsby-wordpress-theme-libre/src/components/meta/website-meta.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ const WebsiteMeta = () => {
6060

6161
shareImage = shareImage ? url.resolve(config.siteUrl, shareImage) : null;
6262

63-
const facebookImageUrl = config.facebookCard.imageUrl ? url.resolve(config.siteUrl, config.facebookCard.imageUrl) : null;
63+
const facebookImageUrl = config.facebookCard.imageUrl
64+
? url.resolve(config.siteUrl, config.facebookCard.imageUrl)
65+
: null;
6466

65-
const twitterImageUrl = config.twitterCard.imageUrl ? url.resolve(config.siteUrl, config.twitterCard.imageUrl) : null;
67+
const twitterImageUrl = config.twitterCard.imageUrl
68+
? url.resolve(config.siteUrl, config.twitterCard.imageUrl)
69+
: null;
6670

6771
const jsonLd = {
6872
"@context": `https://schema.org/`,
@@ -79,12 +83,14 @@ const WebsiteMeta = () => {
7983
publisher: {
8084
"@type": `Organization`,
8185
name: siteTitle,
82-
logo: {
83-
"@type": `ImageObject`,
84-
url: publisherLogo,
85-
width: 60,
86-
height: 60,
87-
},
86+
logo: publisherLogo
87+
? {
88+
"@type": `ImageObject`,
89+
url: publisherLogo,
90+
width: 60,
91+
height: 60,
92+
}
93+
: undefined,
8894
},
8995
mainEntityOfPage: {
9096
"@type": `WebPage`,
@@ -95,7 +101,7 @@ const WebsiteMeta = () => {
95101

96102
return (
97103
<>
98-
<Helmet htmlAttributes={{lang:config.language}}>
104+
<Helmet htmlAttributes={{ lang: config.language }}>
99105
<title>{config.metadata.title || config.siteTitle}</title>
100106
<meta
101107
name="description"

0 commit comments

Comments
 (0)