mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
🐛 Fixed facebook/twitter images having relative URLS in API output
no issue Output serializer's url util was expecting `og_image` and `twitter_image` to be top-level attributes in the `attrs` object but they are actually nested under `posts_meta`. - updated the code to use lodash's `get/set()` so that we can work with paths for easier handling of nested objects - fixed unit tests where the mocked data under test did not match real-world data
This commit is contained in:
parent
58ac033b97
commit
9810c41dca
@ -46,9 +46,10 @@ const forPost = (id, attrs, frame) => {
|
||||
}
|
||||
});
|
||||
|
||||
['feature_image', 'og_image', 'twitter_image', 'canonical_url'].forEach((attr) => {
|
||||
if (attrs[attr]) {
|
||||
attrs[attr] = urlUtils.relativeToAbsolute(attrs[attr]);
|
||||
['feature_image', 'canonical_url', 'posts_meta.og_image', 'posts_meta.twitter_image'].forEach((path) => {
|
||||
const value = _.get(attrs, path);
|
||||
if (value) {
|
||||
_.set(attrs, path, urlUtils.relativeToAbsolute(value));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -56,9 +56,10 @@ const forPost = (id, attrs, frame) => {
|
||||
}
|
||||
});
|
||||
|
||||
['feature_image', 'og_image', 'twitter_image', 'canonical_url'].forEach((attr) => {
|
||||
if (attrs[attr]) {
|
||||
attrs[attr] = urlUtils.relativeToAbsolute(attrs[attr], attrs.url, urlOptions);
|
||||
['feature_image', 'canonical_url', 'posts_meta.og_image', 'posts_meta.twitter_image'].forEach((path) => {
|
||||
const value = _.get(attrs, path);
|
||||
if (value) {
|
||||
_.set(attrs, path, urlUtils.relativeToAbsolute(value));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -36,8 +36,10 @@ describe('Unit: canary/utils/serializers/output/utils/url', function () {
|
||||
codeinjection_head: 'codeinjectionHead',
|
||||
codeinjection_foot: 'codeinjectionFoot',
|
||||
feature_image: 'featureImage',
|
||||
og_image: 'ogImage',
|
||||
twitter_image: 'twitterImage',
|
||||
posts_meta: {
|
||||
og_image: 'ogImage',
|
||||
twitter_image: 'twitterImage'
|
||||
},
|
||||
canonical_url: 'canonicalUrl'
|
||||
}));
|
||||
|
||||
|
@ -36,8 +36,10 @@ describe('Unit: v2/utils/serializers/output/utils/url', function () {
|
||||
codeinjection_head: 'codeinjectionHead',
|
||||
codeinjection_foot: 'codeinjectionFoot',
|
||||
feature_image: 'featureImage',
|
||||
og_image: 'ogImage',
|
||||
twitter_image: 'twitterImage',
|
||||
posts_meta: {
|
||||
og_image: 'ogImage',
|
||||
twitter_image: 'twitterImage'
|
||||
},
|
||||
canonical_url: 'canonicalUrl'
|
||||
}));
|
||||
|
||||
|
@ -36,8 +36,10 @@ describe('Unit: v3/utils/serializers/output/utils/url', function () {
|
||||
codeinjection_head: 'codeinjectionHead',
|
||||
codeinjection_foot: 'codeinjectionFoot',
|
||||
feature_image: 'featureImage',
|
||||
og_image: 'ogImage',
|
||||
twitter_image: 'twitterImage',
|
||||
posts_meta: {
|
||||
og_image: 'ogImage',
|
||||
twitter_image: 'twitterImage'
|
||||
},
|
||||
canonical_url: 'canonicalUrl'
|
||||
}));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user