0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -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:
Hannah Wolfe 2022-12-15 16:10:36 +00:00 committed by GitHub
parent 74cb362f87
commit 5fad27a3c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -272,7 +272,11 @@ class PostsImporter extends BaseImporter {
model.mobiledoc = JSON.stringify(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);
});

View file

@ -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];
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));
posts.length.should.eql(1);
should(posts[0].html).eql(null);
posts[0].mobiledoc.should.eql('{"version":"0.3.1","ghostVersion":"4.0","markups":[],"atoms":[],"cards":[],"sections":[[1,"p",[[0,[],0,""]]]]}');
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","atoms":[],"cards":[],"markups":[],"sections":[[1,"h1",[[0,[],0,"This is my post content."]]]]}');
});
});