mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated twitter/og structured data rules
refs https://github.com/TryGhost/Ghost/issues/10921 refs https://github.com/TryGhost/Ghost/pull/11068 - When there is no twitter or og image specified for a post or a page the new default falls back to appropriate site-wide twitter/og image or site's cover image. - New rules of follback follow this logic: post/page/amp = post.twitter_image || post.feature_image || settings.twitter_image || settings.cover_image; post/page/amp = post.og_image || post.feature_image || settings.og_image || settings.cover_image;
This commit is contained in:
parent
1b1463f8ca
commit
f3e0949c73
5 changed files with 83 additions and 3 deletions
|
@ -17,6 +17,10 @@ function getOgImage(data) {
|
|||
return urlUtils.relativeToAbsolute(contextObject.og_image);
|
||||
} else if (contextObject.feature_image) {
|
||||
return urlUtils.relativeToAbsolute(contextObject.feature_image);
|
||||
} else if (settingsCache.get('og_image')) {
|
||||
return urlUtils.relativeToAbsolute(settingsCache.get('og_image'));
|
||||
} else if (settingsCache.get('cover_image')) {
|
||||
return urlUtils.relativeToAbsolute(settingsCache.get('cover_image'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@ function getTwitterImage(data) {
|
|||
return urlUtils.relativeToAbsolute(contextObject.twitter_image);
|
||||
} else if (contextObject.feature_image) {
|
||||
return urlUtils.relativeToAbsolute(contextObject.feature_image);
|
||||
} else if (settingsCache.get('twitter_image')) {
|
||||
return urlUtils.relativeToAbsolute(settingsCache.get('twitter_image'));
|
||||
} else if (settingsCache.get('cover_image')) {
|
||||
return urlUtils.relativeToAbsolute(settingsCache.get('cover_image'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,18 @@ describe('getOgImage', function () {
|
|||
|
||||
post.feature_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['post'], post})
|
||||
).endWith('settings-og.jpg');
|
||||
|
||||
localSettingsCache.og_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['post'], post})
|
||||
).endWith('settings-cover.jpg');
|
||||
|
||||
localSettingsCache.cover_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['post'], post})
|
||||
).equal(null);
|
||||
|
@ -79,6 +91,18 @@ describe('getOgImage', function () {
|
|||
|
||||
page.feature_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['page'], page})
|
||||
).endWith('settings-og.jpg');
|
||||
|
||||
localSettingsCache.og_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['page'], page})
|
||||
).endWith('settings-cover.jpg');
|
||||
|
||||
localSettingsCache.cover_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['page'], page})
|
||||
).equal(null);
|
||||
|
@ -103,6 +127,18 @@ describe('getOgImage', function () {
|
|||
|
||||
post.feature_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['page'], post})
|
||||
).endWith('settings-og.jpg');
|
||||
|
||||
localSettingsCache.og_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['page'], post})
|
||||
).endWith('settings-cover.jpg');
|
||||
|
||||
localSettingsCache.cover_image = '';
|
||||
|
||||
should(
|
||||
getOgImage({context: ['page'], post})
|
||||
).equal(null);
|
||||
|
|
|
@ -55,6 +55,18 @@ describe('getTwitterImage', function () {
|
|||
|
||||
post.feature_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['post'], post})
|
||||
).endWith('settings-twitter.jpg');
|
||||
|
||||
localSettingsCache.twitter_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['post'], post})
|
||||
).endWith('settings-cover.jpg');
|
||||
|
||||
localSettingsCache.cover_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['post'], post})
|
||||
).equal(null);
|
||||
|
@ -79,6 +91,18 @@ describe('getTwitterImage', function () {
|
|||
|
||||
page.feature_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['page'], page})
|
||||
).endWith('settings-twitter.jpg');
|
||||
|
||||
localSettingsCache.twitter_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['page'], page})
|
||||
).endWith('settings-cover.jpg');
|
||||
|
||||
localSettingsCache.cover_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['page'], page})
|
||||
).equal(null);
|
||||
|
@ -103,6 +127,18 @@ describe('getTwitterImage', function () {
|
|||
|
||||
post.feature_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['page'], post})
|
||||
).endWith('settings-twitter.jpg');
|
||||
|
||||
localSettingsCache.twitter_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['page'], post})
|
||||
).endWith('settings-cover.jpg');
|
||||
|
||||
localSettingsCache.cover_image = '';
|
||||
|
||||
should(
|
||||
getTwitterImage({context: ['page'], post})
|
||||
).equal(null);
|
||||
|
|
|
@ -899,16 +899,16 @@ describe('{{ghost_head}} helper', function () {
|
|||
rendered.string.should.match(/<meta property="og:description" content="site description" \/>/);
|
||||
rendered.string.should.match(/<meta property="og:url" content="http:\/\/localhost:65530\/post\/" \/>/);
|
||||
rendered.string.should.match(/<meta property="article:author" content="https:\/\/www.facebook.com\/testuser" \/>/);
|
||||
rendered.string.should.not.match(/<meta property="og:image"/);
|
||||
rendered.string.should.match(/<meta property="og:image"/);
|
||||
rendered.string.should.match(/<meta property="article:tag" content="tag1" \/>/);
|
||||
rendered.string.should.match(/<meta property="article:tag" content="tag2" \/>/);
|
||||
rendered.string.should.match(/<meta property="article:tag" content="tag3" \/>/);
|
||||
rendered.string.should.match(/<meta name="twitter:card" content="summary" \/>/);
|
||||
rendered.string.should.match(/<meta name="twitter:card" content="summary_large_image" \/>/);
|
||||
rendered.string.should.match(/<meta name="twitter:title" content="Welcome to Ghost" \/>/);
|
||||
rendered.string.should.match(/<meta name="twitter:description" content="site description" \/>/);
|
||||
rendered.string.should.match(/<meta name="twitter:url" content="http:\/\/localhost:65530\/post\/" \/>/);
|
||||
rendered.string.should.match(/<meta name="twitter:creator" content="@testuser" \/>/);
|
||||
rendered.string.should.not.match(/<meta name="twitter:image"/);
|
||||
rendered.string.should.match(/<meta name="twitter:image"/);
|
||||
rendered.string.should.match(/<script type=\"application\/ld\+json\">/);
|
||||
rendered.string.should.match(/"@context": "https:\/\/schema.org"/);
|
||||
rendered.string.should.match(/"@type": "Article"/);
|
||||
|
|
Loading…
Add table
Reference in a new issue