From c90424542e129acab1b819d76ee683e0a7d2d27d Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 29 Jun 2023 14:45:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20signup=20card=20in=20pos?= =?UTF-8?q?t=20plaintext=20and=20email=20preheader=20(#17163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/TryGhost/Team/issues/3542 The signup card text was included in the post plaintext/excerpt and email preheader --- .../services/email-service/cards.test.js | 13 +++++++++---- .../integration/services/email-service/utils.js | 4 ++++ ghost/html-to-plaintext/lib/html-to-plaintext.js | 4 +++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ghost/core/test/integration/services/email-service/cards.test.js b/ghost/core/test/integration/services/email-service/cards.test.js index 52f0908505..6c0abf9006 100644 --- a/ghost/core/test/integration/services/email-service/cards.test.js +++ b/ghost/core/test/integration/services/email-service/cards.test.js @@ -5,10 +5,17 @@ const configUtils = require('../../../utils/configUtils'); const {sendEmail} = require('./utils'); const cheerio = require('cheerio'); +/** + * Remove the preheader span from the email html and put it in a separate field called preheader + * @template {{html: string}} T + * @param {T} data + * @returns {asserts data is T & {preheader: string}} + */ function splitPreheader(data) { // Remove the preheader span from the email using cheerio const $ = cheerio.load(data.html); const preheader = $('.preheader'); + // @ts-ignore data.preheader = preheader.html(); preheader.remove(); data.html = $.html(); @@ -120,10 +127,8 @@ describe('Can send cards via email', function () { // Check the plaintext does contain the paragraph, but doesn't contain the signup card assert.ok(!data.html.includes('Sign up for Koenig Lexical')); - - // This is a bug! The plaintext and preheader should not contain the signup card - //assert.ok(!data.plaintext.includes('Sign up for Koenig Lexical')); - //assert.ok(!data.preheader.includes('Sign up for Koenig Lexical')); + assert.ok(!data.plaintext.includes('Sign up for Koenig Lexical')); + assert.ok(!data.preheader.includes('Sign up for Koenig Lexical')); assert.ok(data.html.includes('This is a paragraph')); assert.ok(data.plaintext.includes('This is a paragraph')); diff --git a/ghost/core/test/integration/services/email-service/utils.js b/ghost/core/test/integration/services/email-service/utils.js index 8f8f3b1532..3081f89cbd 100644 --- a/ghost/core/test/integration/services/email-service/utils.js +++ b/ghost/core/test/integration/services/email-service/utils.js @@ -58,6 +58,10 @@ async function createPublishedPostEmail(agent, settings = {}, email_recipient_fi } let lastEmailModel; +/** + * + * @returns {Promise<{html: string, plaintext: string, emailModel: any, recipientData: any}>} + */ async function sendEmail(agent, settings, email_recipient_filter) { // Prepare a post and email model const completedPromise = jobManager.awaitCompletion('batch-sending-service-job'); diff --git a/ghost/html-to-plaintext/lib/html-to-plaintext.js b/ghost/html-to-plaintext/lib/html-to-plaintext.js index 3b8efc30e5..88e262980d 100644 --- a/ghost/html-to-plaintext/lib/html-to-plaintext.js +++ b/ghost/html-to-plaintext/lib/html-to-plaintext.js @@ -53,7 +53,9 @@ const loadConverters = () => { // Don't output hrs {selector: 'hr', format: 'skip'}, // Don't output > in blockquotes - {selector: 'blockquote', format: 'block'} + {selector: 'blockquote', format: 'block'}, + // Don't include signup cards in excerpts + {selector: '.kg-signup-card', format: 'skip'} ] });