🐛 Fixed X (formerly Twitter) only showing an image when sharing posts

no issue

- switched `summary_large_image` for `summary` in the `twitter:card` metadata because X no longer includes a summary with the image making sharing links awkward
This commit is contained in:
Kevin Ansfield 2023-11-20 13:27:18 +00:00
parent 320eaac4c4
commit 8be5ea1462
No known key found for this signature in database
4 changed files with 214 additions and 221 deletions

View File

@ -30,7 +30,7 @@
<meta name="twitter:image" content="{{img_url @site.cover_image absolute="true"}}"> <meta name="twitter:image" content="{{img_url @site.cover_image absolute="true"}}">
{{/if}} {{/if}}
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@ghost"> <meta name="twitter:site" content="@ghost">
<meta property="article:publisher" content="https://www.facebook.com/ghost"> <meta property="article:publisher" content="https://www.facebook.com/ghost">
<meta name="referrer" content="no-referrer-when-downgrade"> <meta name="referrer" content="no-referrer-when-downgrade">

View File

@ -1,14 +1,7 @@
const socialUrls = require('@tryghost/social-urls'); const socialUrls = require('@tryghost/social-urls');
function getStructuredData(metaData) { function getStructuredData(metaData) {
let structuredData; let structuredData = {
let card = 'summary';
if (metaData.twitterImage || metaData.coverImage.url) {
card = 'summary_large_image';
}
structuredData = {
'og:site_name': metaData.site.title, 'og:site_name': metaData.site.title,
'og:type': metaData.ogType, 'og:type': metaData.ogType,
'og:title': metaData.ogTitle, 'og:title': metaData.ogTitle,
@ -23,7 +16,7 @@ function getStructuredData(metaData) {
'article:tag': metaData.keywords, 'article:tag': metaData.keywords,
'article:publisher': metaData.site.facebook ? socialUrls.facebook(metaData.site.facebook) : undefined, 'article:publisher': metaData.site.facebook ? socialUrls.facebook(metaData.site.facebook) : undefined,
'article:author': metaData.authorFacebook ? socialUrls.facebook(metaData.authorFacebook) : undefined, 'article:author': metaData.authorFacebook ? socialUrls.facebook(metaData.authorFacebook) : undefined,
'twitter:card': card, 'twitter:card': 'summary',
'twitter:title': metaData.twitterTitle, 'twitter:title': metaData.twitterTitle,
'twitter:description': metaData.twitterDescription, 'twitter:description': metaData.twitterDescription,
'twitter:url': metaData.canonicalUrl, 'twitter:url': metaData.canonicalUrl,

View File

@ -52,7 +52,7 @@ describe('getStructuredData', function () {
'og:title': 'Post Title', 'og:title': 'Post Title',
'og:type': 'article', 'og:type': 'article',
'og:url': 'http://mysite.com/post/my-post-slug/', 'og:url': 'http://mysite.com/post/my-post-slug/',
'twitter:card': 'summary_large_image', 'twitter:card': 'summary',
'twitter:data1': 'Test User', 'twitter:data1': 'Test User',
'twitter:data2': ['one', 'two', 'tag'].join(', '), 'twitter:data2': ['one', 'two', 'tag'].join(', '),
'twitter:description': 'Post meta description', 'twitter:description': 'Post meta description',
@ -114,7 +114,7 @@ describe('getStructuredData', function () {
'og:title': 'Custom Facebook title', 'og:title': 'Custom Facebook title',
'og:type': 'article', 'og:type': 'article',
'og:url': 'http://mysite.com/post/my-post-slug/', 'og:url': 'http://mysite.com/post/my-post-slug/',
'twitter:card': 'summary_large_image', 'twitter:card': 'summary',
'twitter:data1': 'Test User', 'twitter:data1': 'Test User',
'twitter:data2': ['one', 'two', 'tag'].join(', '), 'twitter:data2': ['one', 'two', 'tag'].join(', '),
'twitter:description': 'Custom Twitter description', 'twitter:description': 'Custom Twitter description',