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

Implemented post slug update on duplicated post title update (#16802)

no issue

Updated the slug generation logic so that when a post is duplicated and
the title is edited, the slug gets updated to reflect the new title of
the post
This commit is contained in:
Michael Barrett 2023-05-16 10:47:40 +01:00 committed by GitHub
parent f9866f97ae
commit 43f55521c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,8 @@ import {isInvalidError} from 'ember-ajax/errors';
import {inject as service} from '@ember/service';
const DEFAULT_TITLE = '(Untitled)';
// suffix that is applied to the title of a post when it has been duplicated
const DUPLICATED_POST_TITLE_SUFFIX = '(Copy)';
// time in ms to save after last content edit
const AUTOSAVE_TIMEOUT = 3000;
// time in ms to force a save if the user is continuously typing
@ -726,9 +727,15 @@ export default class LexicalEditorController extends Controller {
// this is necessary to force a save when the title is blank
this.set('hasDirtyAttributes', true);
// generate a slug if a post is new and doesn't have a title yet or
// if the title is still '(Untitled)'
if ((post.get('isNew') && !currentTitle) || currentTitle === DEFAULT_TITLE) {
// generate slug if post
// - is new and doesn't have a title yet
// - still has the default title
// - previously had a title that ended with the duplicated post title suffix
if (
(post.get('isNew') && !currentTitle) ||
(currentTitle === DEFAULT_TITLE) ||
currentTitle.endsWith(DUPLICATED_POST_TITLE_SUFFIX)
) {
yield this.generateSlugTask.perform();
}