mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
✨ Added html -> mobiledoc conversion to the importer (#16016)
- Now that the importer runs in a job, it seems sensble that we should do this - If posts are imported with HTML set, but not mobiledoc, we now convert html -> mobiledoc - Note: This also converts the mobiledoc -> html so _may_ be lossy - Without this, imports that only have HTML, not mobiledoc, would have resulted in empty posts, so lossy > empty
This commit is contained in:
parent
74cb362f87
commit
5fad27a3c0
2 changed files with 7 additions and 3 deletions
|
@ -272,7 +272,11 @@ class PostsImporter extends BaseImporter {
|
||||||
|
|
||||||
model.mobiledoc = JSON.stringify(mobiledoc);
|
model.mobiledoc = JSON.stringify(mobiledoc);
|
||||||
model.html = mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(model.mobiledoc));
|
model.html = mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(model.mobiledoc));
|
||||||
|
} else if (model.html) {
|
||||||
|
model.mobiledoc = JSON.stringify(mobiledocLib.htmlToMobiledocConverter(model.html));
|
||||||
|
model.html = mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(model.mobiledoc));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sanitizePostsMeta(model);
|
this.sanitizePostsMeta(model);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ describe('Importer 1.0', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('mobiledoc is null, html field is set', function () {
|
it('mobiledoc is null, html field is set, convert html -> mobiledoc', function () {
|
||||||
const exportData = exportedBodyV1().db[0];
|
const exportData = exportedBodyV1().db[0];
|
||||||
|
|
||||||
exportData.data.posts[0] = testUtils.DataGenerator.forKnex.createPost({
|
exportData.data.posts[0] = testUtils.DataGenerator.forKnex.createPost({
|
||||||
|
@ -95,8 +95,8 @@ describe('Importer 1.0', function () {
|
||||||
const posts = result[0].data.map(model => model.toJSON(options));
|
const posts = result[0].data.map(model => model.toJSON(options));
|
||||||
|
|
||||||
posts.length.should.eql(1);
|
posts.length.should.eql(1);
|
||||||
should(posts[0].html).eql(null);
|
should(posts[0].html).eql('<h1 id="this-is-my-post-content">This is my post content.</h1>');
|
||||||
posts[0].mobiledoc.should.eql('{"version":"0.3.1","ghostVersion":"4.0","markups":[],"atoms":[],"cards":[],"sections":[[1,"p",[[0,[],0,""]]]]}');
|
posts[0].mobiledoc.should.eql('{"version":"0.3.1","atoms":[],"cards":[],"markups":[],"sections":[[1,"h1",[[0,[],0,"This is my post content."]]]]}');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue