mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated PostRevisions to accept html string
- We also fix the name of the feature flag - We also correctly await the result of revision generation - We pass the HTML string so we can potentially do an easier word count diff
This commit is contained in:
parent
79a95268b6
commit
a507072eb8
3 changed files with 39 additions and 24 deletions
|
@ -864,8 +864,8 @@ Post = ghostBookshelf.Model.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.hasChanged('lexical') && !model.get('mobiledoc') && !options.importing && !options.migrating) {
|
if (!labs.isSet('postHistory')) {
|
||||||
if (!labs.isSet('postsHistory')) {
|
if (model.hasChanged('lexical') && !model.get('mobiledoc') && !options.importing && !options.migrating) {
|
||||||
ops.push(function updateRevisions() {
|
ops.push(function updateRevisions() {
|
||||||
return ghostBookshelf.model('PostRevision')
|
return ghostBookshelf.model('PostRevision')
|
||||||
.findAll(Object.assign({
|
.findAll(Object.assign({
|
||||||
|
@ -895,7 +895,9 @@ Post = ghostBookshelf.Model.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
} else {
|
||||||
|
if (!model.get('mobiledoc') && !options.importing && !options.migrating) {
|
||||||
const postRevisions = new PostRevisions({
|
const postRevisions = new PostRevisions({
|
||||||
config: {
|
config: {
|
||||||
max_revisions: POST_REVISIONS_COUNT
|
max_revisions: POST_REVISIONS_COUNT
|
||||||
|
@ -911,17 +913,17 @@ Post = ghostBookshelf.Model.extend({
|
||||||
const revisions = revisionModels.toJSON();
|
const revisions = revisionModels.toJSON();
|
||||||
const previous = {
|
const previous = {
|
||||||
id: model.id,
|
id: model.id,
|
||||||
lexical: model.previous('lexical')
|
lexical: model.previous('lexical'),
|
||||||
|
html: model.previous('html')
|
||||||
};
|
};
|
||||||
const current = {
|
const current = {
|
||||||
id: model.id,
|
id: model.id,
|
||||||
lexical: model.get('lexical')
|
lexical: model.get('lexical'),
|
||||||
|
html: model.get('html')
|
||||||
};
|
};
|
||||||
|
|
||||||
model.set(
|
const newRevisions = await postRevisions.getRevisions(previous, current, revisions);
|
||||||
'post_revisions',
|
model.set('post_revisions', newRevisions);
|
||||||
postRevisions.getRevisions(previous, current, revisions)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* @typedef {object} PostLike
|
* @typedef {object} PostLike
|
||||||
* @property {string} id
|
* @property {string} id
|
||||||
* @property {string} lexical
|
* @property {string} lexical
|
||||||
|
* @property {string} html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +35,7 @@ class PostRevisions {
|
||||||
if (revisions.length === 0) {
|
if (revisions.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return previous.lexical !== current.lexical;
|
return previous.html !== current.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,14 +25,16 @@ describe('PostRevisions', function () {
|
||||||
assert.equal(actual, expected);
|
assert.equal(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if the current and previous lexical values are the same', function () {
|
it('should return false if the current and previous html values are the same', function () {
|
||||||
const postRevisions = new PostRevisions({config});
|
const postRevisions = new PostRevisions({config});
|
||||||
|
|
||||||
const expected = false;
|
const expected = false;
|
||||||
const actual = postRevisions.shouldGenerateRevision({
|
const actual = postRevisions.shouldGenerateRevision({
|
||||||
lexical: 'blah'
|
lexical: 'previous',
|
||||||
|
html: 'blah'
|
||||||
}, {
|
}, {
|
||||||
lexical: 'blah'
|
lexical: 'current',
|
||||||
|
html: 'blah'
|
||||||
}, [{
|
}, [{
|
||||||
lexical: 'blah'
|
lexical: 'blah'
|
||||||
}]);
|
}]);
|
||||||
|
@ -40,14 +42,16 @@ describe('PostRevisions', function () {
|
||||||
assert.equal(actual, expected);
|
assert.equal(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if the current and previous lexical values are different', function () {
|
it('should return true if the current and previous html values are different', function () {
|
||||||
const postRevisions = new PostRevisions({config});
|
const postRevisions = new PostRevisions({config});
|
||||||
|
|
||||||
const expected = true;
|
const expected = true;
|
||||||
const actual = postRevisions.shouldGenerateRevision({
|
const actual = postRevisions.shouldGenerateRevision({
|
||||||
lexical: 'blah'
|
lexical: 'blah',
|
||||||
|
html: 'blah'
|
||||||
}, {
|
}, {
|
||||||
lexical: 'blah2'
|
lexical: 'blah',
|
||||||
|
html: 'blah2'
|
||||||
}, [{
|
}, [{
|
||||||
lexical: 'blah'
|
lexical: 'blah'
|
||||||
}]);
|
}]);
|
||||||
|
@ -77,9 +81,11 @@ describe('PostRevisions', function () {
|
||||||
lexical: 'revision'
|
lexical: 'revision'
|
||||||
}];
|
}];
|
||||||
const actual = await postRevisions.getRevisions({
|
const actual = await postRevisions.getRevisions({
|
||||||
lexical: 'blah'
|
lexical: 'blah',
|
||||||
|
html: 'blah'
|
||||||
}, {
|
}, {
|
||||||
lexical: 'blah'
|
lexical: 'blah',
|
||||||
|
html: 'blah'
|
||||||
}, [{
|
}, [{
|
||||||
lexical: 'revision'
|
lexical: 'revision'
|
||||||
}]);
|
}]);
|
||||||
|
@ -92,10 +98,12 @@ describe('PostRevisions', function () {
|
||||||
|
|
||||||
const actual = await postRevisions.getRevisions({
|
const actual = await postRevisions.getRevisions({
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'previous'
|
lexical: 'previous',
|
||||||
|
html: 'previous'
|
||||||
}, {
|
}, {
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'current'
|
lexical: 'current',
|
||||||
|
html: 'current'
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
assert.equal(actual.length, 2);
|
assert.equal(actual.length, 2);
|
||||||
|
@ -112,18 +120,22 @@ describe('PostRevisions', function () {
|
||||||
|
|
||||||
const revisions = await postRevisions.getRevisions({
|
const revisions = await postRevisions.getRevisions({
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'previous'
|
lexical: 'previous',
|
||||||
|
html: 'previous'
|
||||||
}, {
|
}, {
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'current'
|
lexical: 'current',
|
||||||
|
html: 'current'
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const actual = await postRevisions.getRevisions({
|
const actual = await postRevisions.getRevisions({
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'old'
|
lexical: 'old',
|
||||||
|
html: 'old'
|
||||||
}, {
|
}, {
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'new'
|
lexical: 'new',
|
||||||
|
html: 'new'
|
||||||
}, revisions);
|
}, revisions);
|
||||||
|
|
||||||
assert.equal(actual.length, 2);
|
assert.equal(actual.length, 2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue