0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛 Fixed cardWidth being lost on 2.0 imports (#10068)

no issue

- When importing Ghost 2.0 blogs into 2.0 blogs...
- The Koenig image card would lose it's cardWidth setting,
- because it'd be overridden by the imageStyle setting, which was null
- The importer previous _only_ kept the width if importing 1.0 blogs
This commit is contained in:
Hannah Wolfe 2018-10-26 10:30:39 +01:00 committed by Katharina Irrgang
parent 3f91a9e8a2
commit 275d82199f
2 changed files with 69 additions and 1 deletions

View file

@ -164,6 +164,7 @@ class PostsImporter extends BaseImporter {
// CASE 1: you are importing old editor posts
// CASE 2: you are importing Koenig Beta posts
// CASE 3: you are importing Koenig 2.0 posts
if (model.mobiledoc || (model.mobiledoc && model.html && model.html.match(/^<div class="kg-card-markdown">/))) {
let mobiledoc;
@ -179,7 +180,8 @@ class PostsImporter extends BaseImporter {
}
mobiledoc.cards.forEach((card) => {
if (card[0] === 'image') {
// Koenig Beta = imageStyle, Ghost 2.0 Koenig = cardWidth
if (card[0] === 'image' && card[1].imageStyle) {
card[1].cardWidth = card[1].imageStyle;
delete card[1].imageStyle;
}

View file

@ -1006,6 +1006,72 @@ describe('Integration: Importer', function () {
posts[2].authors[2].id.should.eql(users[3].id);
});
});
it('import 2.0 Koenig post format', ()=> {
const exportData = exportedLatestBody().db[0];
exportData.data.posts[0] = testUtils.DataGenerator.forKnex.createPost({
slug: 'post1',
mobiledoc: JSON.stringify({
version: '0.3.1',
markups: [],
atoms: [],
cards: [
['image', {
src: 'source',
cardWidth: 'wide',
}],
['markdown', {
cardName: 'markdown',
markdown: '# Post Content'
}]
],
sections: [[10,0],[10,1]]
})
});
delete exportData.data.posts[0].html;
exportData.data.posts[1] = testUtils.DataGenerator.forKnex.createPost({
slug: 'post2',
mobiledoc: JSON.stringify({
version: '0.3.1',
markups: [],
atoms: [],
cards: [
['markdown', {
cardName: 'markdown',
markdown: '## Post Content'
}],
['image', {
src: 'source2',
cardWidth: 'not-wide'
}]
],
sections: [[10,0],[10,1]]
}),
html: '<div class="kg-post"><h2 id="postcontent">Post Content</h2></div>\n'
});
const options = Object.assign({formats: 'mobiledoc,html'}, testUtils.context.internal);
return dataImporter.doImport(exportData, importOptions)
.then(function () {
return Promise.all([
models.Post.findPage(options)
]);
}).then(function (result) {
const posts = result[0].data.map((model) => model.toJSON(options));
posts.length.should.eql(2);
posts[0].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["markdown",{"cardName":"markdown","markdown":"## Post Content"}],["image",{"src":"source2","cardWidth":"not-wide"}]],"sections":[[10,0],[10,1]]}');
posts[0].html.should.eql('<h2 id="postcontent">Post Content</h2>\n<figure class="kg-card kg-image-card kg-width-not-wide"><img src="source2" class="kg-image"></figure>');
posts[1].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["image",{"src":"source","cardWidth":"wide"}],["markdown",{"cardName":"markdown","markdown":"# Post Content"}]],"sections":[[10,0],[10,1]]}');
posts[1].html.should.eql('<figure class="kg-card kg-image-card kg-width-wide"><img src="source" class="kg-image"></figure><h1 id="postcontent">Post Content</h1>\n');
});
});
});
describe('Existing database', function () {