Set mobiledoc.ghostVersion: '3.0' if missing on imported content

refs https://github.com/TryGhost/Ghost/issues/12646

- if the version is missing then the content was created before Ghost 4.0
- setting the version to `'3.0'` means it will continue to use the same rendering output so there are no unexpected breaking changes when migrating content
This commit is contained in:
Kevin Ansfield 2021-02-16 12:08:40 +00:00
parent 77f75808a7
commit 2d091fa8f9
2 changed files with 9 additions and 6 deletions

View File

@ -216,6 +216,12 @@ class PostsImporter extends BaseImporter {
mobiledoc = mobiledocLib.blankDocument;
}
// ghostVersion was introduced in 4.0. Any earlier content won't have it set
// so we should set it to "3.0" to match rendering output
if (!mobiledoc.ghostVersion) {
mobiledoc.ghostVersion = '3.0';
}
mobiledoc.cards.forEach((card) => {
// Ghost 1.0 markdown card = 'card-markdown', Ghost 2.0 markdown card = 'markdown'
if (card[0] === 'card-markdown') {

View File

@ -1145,7 +1145,6 @@ describe('Integration: Importer', function () {
slug: 'post1',
mobiledoc: JSON.stringify({
version: '0.3.1',
ghostVersion: '3.0', // 3.0 is when ghostVersion was introduced
markups: [],
atoms: [],
cards: [
@ -1175,7 +1174,7 @@ describe('Integration: Importer', function () {
posts.length.should.eql(1);
posts[0].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["image",{"src":"source","cardWidth":"wide"}],["markdown",{"markdown":"# Post Content"}]],"sections":[[10,0],[10,1]]}');
posts[0].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["image",{"src":"source","cardWidth":"wide"}],["markdown",{"markdown":"# Post Content"}]],"sections":[[10,0],[10,1]],"ghostVersion":"3.0"}');
posts[0].html.should.eql('<figure class="kg-card kg-image-card kg-width-wide"><img src="source" class="kg-image" alt></figure><!--kg-card-begin: markdown--><h1 id="postcontent">Post Content</h1>\n<!--kg-card-end: markdown-->');
});
});
@ -1187,7 +1186,6 @@ describe('Integration: Importer', function () {
slug: 'post1',
mobiledoc: JSON.stringify({
version: '0.3.1',
ghostVersion: '3.0', // 3.0 is when ghostVersion was introduced
markups: [],
atoms: [],
cards: [
@ -1209,7 +1207,6 @@ describe('Integration: Importer', function () {
slug: 'post2',
mobiledoc: JSON.stringify({
version: '0.3.1',
ghostVersion: '3.0',
markups: [],
atoms: [],
cards: [
@ -1238,10 +1235,10 @@ describe('Integration: Importer', function () {
posts.length.should.eql(2);
posts[0].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["markdown",{"markdown":"## Post Content"}],["image",{"src":"source2","cardWidth":"not-wide"}]],"sections":[[10,0],[10,1]]}');
posts[0].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["markdown",{"markdown":"## Post Content"}],["image",{"src":"source2","cardWidth":"not-wide"}]],"sections":[[10,0],[10,1]],"ghostVersion":"3.0"}');
posts[0].html.should.eql('<!--kg-card-begin: markdown--><h2 id="postcontent">Post Content</h2>\n<!--kg-card-end: markdown--><figure class="kg-card kg-image-card kg-width-not-wide"><img src="source2" class="kg-image" alt></figure>');
posts[1].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["image",{"src":"source","cardWidth":"wide"}],["markdown",{"markdown":"# Post Content"}]],"sections":[[10,0],[10,1]]}');
posts[1].mobiledoc.should.eql('{"version":"0.3.1","markups":[],"atoms":[],"cards":[["image",{"src":"source","cardWidth":"wide"}],["markdown",{"markdown":"# Post Content"}]],"sections":[[10,0],[10,1]],"ghostVersion":"3.0"}');
posts[1].html.should.eql('<figure class="kg-card kg-image-card kg-width-wide"><img src="source" class="kg-image" alt></figure><!--kg-card-begin: markdown--><h1 id="postcontent">Post Content</h1>\n<!--kg-card-end: markdown-->');
});
});