Skip to content

Commit c92b2f3

Browse files
committed
Refactor OpenGraph image handling to avoid using default fallback; ensure images are only passed when available.
1 parent d3645d4 commit c92b2f3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

themes/icarus/layout/common/head.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ module.exports = class extends Component {
8282
images.push(img[1]);
8383
}
8484
} else {
85-
images = [url_for('/img/og_image.png')];
85+
// Do NOT use the theme default og_image.png as a fallback image for every page.
86+
// When no page-specific image/thumbnail/cover is present, leave images empty so
87+
// social platforms will not show the Icarus logo as the share thumbnail.
88+
images = [];
8689
}
8790

8891
let adsenseClientId = null;
@@ -101,6 +104,11 @@ module.exports = class extends Component {
101104
openGraphImages = page.photos;
102105
}
103106

107+
// Only pass images prop to OpenGraph when we actually have images.
108+
const openGraphImagesProp = (Array.isArray(openGraphImages) && openGraphImages.length) || typeof openGraphImages === 'string'
109+
? openGraphImages
110+
: undefined;
111+
104112
let structuredImages = images;
105113
if ((typeof structured_data === 'object' && structured_data !== null)
106114
&& ((Array.isArray(structured_data.image) && structured_data.image.length > 0) || typeof structured_data.image === 'string')) {
@@ -109,6 +117,10 @@ module.exports = class extends Component {
109117
structuredImages = page.photos;
110118
}
111119

120+
const structuredImagesProp = (Array.isArray(structuredImages) && structuredImages.length) || typeof structuredImages === 'string'
121+
? structuredImages
122+
: undefined;
123+
112124
let followItVerificationCode = null;
113125
if (Array.isArray(config.widgets)) {
114126
const widget = config.widgets.find(widget => widget.type === 'followit');
@@ -141,7 +153,7 @@ module.exports = class extends Component {
141153
description={open_graph.description || page.description || page.excerpt || page.content || config.description}
142154
keywords={(page.tags && page.tags.length ? page.tags : undefined) || config.keywords}
143155
url={open_graph.url || page.permalink || url}
144-
images={openGraphImages}
156+
images={openGraphImagesProp}
145157
siteName={open_graph.site_name || config.title}
146158
language={language}
147159
twitterId={open_graph.twitter_id}
@@ -160,7 +172,7 @@ module.exports = class extends Component {
160172
publisherLogo={structured_data.publisher_logo || config.logo}
161173
date={page.date}
162174
updated={page.updated}
163-
images={structuredImages} /> : null}
175+
images={structuredImagesProp} /> : null}
164176

165177
{canonical_url ? <link rel="canonical" href={canonical_url} /> : null}
166178
{rss ? <link rel="alternate" href={url_for(rss)} title={config.title} type="application/atom+xml" /> : null}

0 commit comments

Comments
 (0)