Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Reverted: Fixed image URL to be stored as relative in mobiledoc #10632

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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