mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Fixed email preview text with new stability flow (#15996)
closes https://github.com/TryGhost/Team/issues/2382
The preview text is getting set to subject line in the new email flow so it repeats multiple times in the inbox(subject+preview+title). This was because the new flow doesn't use the post serialisation that the old system did, causing excerpt to be empty in the email rendering.
Old system was using post serialisation here -
a721e4f2d7/ghost/core/core/server/services/mega/post-email-serializer.js (L136-L139)
.
This change adds explicit method to calculate the preview text for email in email renderer service using same logic as used in old system.
Co-authored-by: Simon Backx <git@simonbackx.com>
This commit is contained in:
parent
47cd7a7095
commit
a09e86da05
2 changed files with 32 additions and 1 deletions
|
@ -476,6 +476,25 @@ class EmailRenderer {
|
|||
return this.#renderTemplate(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email preheader text from post model
|
||||
* @param {object} postModel
|
||||
* @returns
|
||||
*/
|
||||
#getEmailPreheader(postModel) {
|
||||
let plaintext = postModel.get('plaintext');
|
||||
let customExcerpt = postModel.get('custom_excerpt');
|
||||
if (customExcerpt) {
|
||||
return customExcerpt;
|
||||
} else {
|
||||
if (plaintext) {
|
||||
return plaintext.substring(0, 500);
|
||||
} else {
|
||||
return `${postModel.get('title')} – `;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
@ -535,7 +554,7 @@ class EmailRenderer {
|
|||
image: this.#settingsCache.get('icon')
|
||||
}, true) : null
|
||||
},
|
||||
preheader: post.get('excerpt') ? post.get('excerpt') : `${post.get('title')} – `,
|
||||
preheader: this.#getEmailPreheader(post),
|
||||
html,
|
||||
|
||||
post: {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const EmailRenderer = require('../lib/email-renderer');
|
||||
const assert = require('assert');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
describe('Email renderer', function () {
|
||||
describe('buildReplacementDefinitions', function () {
|
||||
|
@ -367,6 +368,14 @@ describe('Email renderer', function () {
|
|||
if (key === 'title') {
|
||||
return 'Test Post';
|
||||
}
|
||||
|
||||
if (key === 'plaintext') {
|
||||
return 'Test plaintext for post';
|
||||
}
|
||||
|
||||
if (key === 'custom_excerpt') {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
getLazyRelation: () => {
|
||||
return {
|
||||
|
@ -410,9 +419,12 @@ describe('Email renderer', function () {
|
|||
options
|
||||
);
|
||||
|
||||
const $ = cheerio.load(response.html);
|
||||
|
||||
response.plaintext.should.containEql('Test Post');
|
||||
response.plaintext.should.containEql('Unsubscribe [%%{unsubscribe_url}%%]');
|
||||
response.plaintext.should.containEql('http://example.com');
|
||||
should($('.preheader').text()).eql('Test plaintext for post');
|
||||
response.html.should.containEql('Test Post');
|
||||
response.html.should.containEql('Unsubscribe');
|
||||
response.html.should.containEql('http://example.com');
|
||||
|
|
Loading…
Add table
Reference in a new issue