mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
🐛 Fixed slug not always updating for draft posts (#21691)
ref https://linear.app/ghost/issue/ONC-548/ There have been reported cases of the editor not updating the slug for draft posts. The logic should be as follows: for a draft post, if the title was updated and we do not detect a custom slug, update it. This got out of sync due to actions where the save was triggered but the title onBlur effect (which updates the slug) was not triggered. This has been resolved by evaluating the slug in the before save actions.
This commit is contained in:
parent
3277da7140
commit
7083bd0628
@ -734,26 +734,19 @@ export default class LexicalEditorController extends Controller {
|
||||
}
|
||||
|
||||
@task
|
||||
*beforeSaveTask(options = {}) {
|
||||
*beforeSaveTask() {
|
||||
if (this.post?.isDestroyed || this.post?.isDestroying) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ensure we remove any blank cards when performing a full save
|
||||
if (!options.backgroundSave) {
|
||||
// TODO: not yet implemented in react editor
|
||||
// if (this._koenig) {
|
||||
// this._koenig.cleanup();
|
||||
// this.set('hasDirtyAttributes', true);
|
||||
// }
|
||||
if (this.post.status === 'draft') {
|
||||
if (this.post.titleScratch !== this.post.title) {
|
||||
yield this.generateSlugTask.perform();
|
||||
}
|
||||
}
|
||||
|
||||
// Set the properties that are indirected
|
||||
|
||||
// Set lexical equal to what's in the editor
|
||||
this.set('post.lexical', this.post.lexicalScratch || null);
|
||||
|
||||
// Set a default title
|
||||
if (!this.post.titleScratch?.trim()) {
|
||||
this.set('post.titleScratch', DEFAULT_TITLE);
|
||||
}
|
||||
@ -774,7 +767,6 @@ export default class LexicalEditorController extends Controller {
|
||||
|
||||
if (!this.get('post.slug')) {
|
||||
this.saveTitleTask.cancelAll();
|
||||
|
||||
yield this.generateSlugTask.perform();
|
||||
}
|
||||
}
|
||||
|
@ -623,6 +623,24 @@ describe('Acceptance: Editor', function () {
|
||||
expect(find('[data-test-editor-post-status]')).to.contain.text('New');
|
||||
});
|
||||
|
||||
it('updates slug when title changes without blur', async function () {
|
||||
let post = this.server.create('post', {authors: [author]});
|
||||
|
||||
await visit(`/editor/post/${post.id}`);
|
||||
await fillIn('[data-test-editor-title-input]', 'Test Title');
|
||||
|
||||
await triggerEvent('[data-test-editor-title-input]', 'keydown', {
|
||||
keyCode: 83, // s
|
||||
metaKey: ctrlOrCmd === 'command',
|
||||
ctrlKey: ctrlOrCmd === 'ctrl'
|
||||
});
|
||||
|
||||
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
|
||||
let body = JSON.parse(lastRequest.requestBody);
|
||||
expect(body.posts[0].slug).to.equal('test-title');
|
||||
expect(post.slug).to.equal('test-title');
|
||||
});
|
||||
|
||||
it('handles TKs in title', async function () {
|
||||
let post = this.server.create('post', {authors: [author]});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user