From 8db947cd241d4fcb02b12273c669aa26333f0473 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 3 Jan 2023 20:15:32 +0000 Subject: [PATCH] Trim generated post slug length in Revue importer (#16065) refs: https://github.com/TryGhost/Ghost/commit/5f90baf6fe3bd9b9acdcc418a0e21389084030ee - Ghost has a character limit on post slugs of 191 characters, - Sometimes, the slug that is generated from the title in Revue content is longer than this, causing the import to fail. - This PR trims that generated post slug to 190 characters. --- ghost/importer-revue/lib/importer-revue.js | 3 ++- .../importer-revue/test/importer-revue.test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ghost/importer-revue/lib/importer-revue.js b/ghost/importer-revue/lib/importer-revue.js index afafcbdca7..2ef598cb33 100644 --- a/ghost/importer-revue/lib/importer-revue.js +++ b/ghost/importer-revue/lib/importer-revue.js @@ -44,11 +44,12 @@ const fetchPostsFromData = (revueData) => { } const postDate = JSONToHTML.getPostDate(postMeta); + const postSlug = slugify(postMeta.subject).slice(0, 190); posts.push({ comment_id: revuePostID, title: postMeta.subject, - slug: slugify(postMeta.subject), + slug: postSlug, status: JSONToHTML.getPostStatus(postMeta), visibility: 'public', created_at: postDate, diff --git a/ghost/importer-revue/test/importer-revue.test.js b/ghost/importer-revue/test/importer-revue.test.js index 791107c4aa..d36f545673 100644 --- a/ghost/importer-revue/test/importer-revue.test.js +++ b/ghost/importer-revue/test/importer-revue.test.js @@ -113,6 +113,24 @@ describe('Revue Importer', function () { } ]); }); + + it('can trim generated post slug length', function () { + const result = RevueImporter.importPosts({items: '[]', issues: 'id,description,sent_at,subject,preheader\n123456,"

Hello World!

",2022-12-01 01:01:30 UTC,Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Mauris Convallis Et Metus Eu Blandit Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Ut Porta Dapibus Massa Condimentum Malesuada Ipsum Scelerisque Nec Vestibulum Sed Placerat Cras,'}); + + assert.deepEqual(result, [ + { + comment_id: 123456, + title: 'Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Mauris Convallis Et Metus Eu Blandit Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Ut Porta Dapibus Massa Condimentum Malesuada Ipsum Scelerisque Nec Vestibulum Sed Placerat Cras', + slug: 'lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit-mauris-convallis-et-metus-eu-blandit-lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit-ut-porta-dapibus-massa-condimentum-malesuad', + status: 'published', + visibility: 'public', + created_at: '2022-12-01T01:01:30.000Z', + published_at: '2022-12-01T01:01:30.000Z', + updated_at: '2022-12-01T01:01:30.000Z', + html: '

Hello World!

' + } + ]); + }); }); describe('importSubscribers', function () {