Skip to content

Commit

Permalink
Reverted: Fixed image URL to be stored as relative in mobiledoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Mar 22, 2019
1 parent 1e6f4ba commit 5465cc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions core/server/api/v2/utils/serializers/input/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const _ = require('lodash');
const {absoluteToRelative, getBlogUrl, STATIC_IMAGE_URL_PREFIX} = require('../../../../../../services/url/utils');

const handleCanonicalUrl = (url) => {
Expand All @@ -24,6 +23,7 @@ const handleImageUrl = (imageUrl) => {
return imageUrl;
};

/*
const handleContentUrls = (content) => {
const blogDomain = getBlogUrl().replace(/^http(s?):\/\//, '').replace(/\/$/, '');
const imagePathRe = new RegExp(`(http(s?)://)?${blogDomain}/${STATIC_IMAGE_URL_PREFIX}`, 'g');
Expand All @@ -39,12 +39,20 @@ const handleContentUrls = (content) => {
return content;
};
*/

const forPost = (attrs, options) => {
// make all content image URLs relative, ref: https://github.com/TryGhost/Ghost/issues/10477
if (attrs.mobiledoc) {
attrs.mobiledoc = handleContentUrls(attrs.mobiledoc);
}
/**
* NOTE: make all content image URLs relative, ref: https://github.com/TryGhost/Ghost/issues/10477
*
* if (attrs.mobiledoc) {
* attrs.mobiledoc = handleContentUrls(attrs.mobiledoc);
* }
*
* @TODO: It's really hard to transform the links back from relative to absolute in mobiledoc.
* We will store absolute urls for now. It's less error-prone than reg exing mobiledoc incorrectly.
* Refs https://github.com/TryGhost/Ghost/issues/10477
*/

if (attrs.feature_image) {
attrs.feature_image = handleImageUrl(attrs.feature_image);
Expand Down
4 changes: 2 additions & 2 deletions core/test/unit/api/v2/utils/serializers/input/posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
serializers.input.posts.edit(apiConfig, frame);

let postData = frame.data.posts[0];
postData.mobiledoc.should.equal('{"version":"0.3.1","atoms":[],"cards":[["image",{"src":"/content/images/2019/02/image.jpg"}]]}');
postData.mobiledoc.should.equal('{"version":"0.3.1","atoms":[],"cards":[["image",{"src":"https://mysite.com/content/images/2019/02/image.jpg"}]]}');
});

it('when mobiledoc contains multiple absolute URLs to images with different protocols', function () {
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
serializers.input.posts.edit(apiConfig, frame);

let postData = frame.data.posts[0];
postData.mobiledoc.should.equal('{"version":"0.3.1","atoms":[],"cards":[["image",{"src":"/content/images/2019/02/image.jpg"}],["image",{"src":"/content/images/2019/02/image.png"}]]');
postData.mobiledoc.should.equal('{"version":"0.3.1","atoms":[],"cards":[["image",{"src":"https://mysite.com/content/images/2019/02/image.jpg"}],["image",{"src":"http://mysite.com/content/images/2019/02/image.png"}]]');
});

it('when blog url is without subdir', function () {
Expand Down

0 comments on commit 5465cc0

Please sign in to comment.